2017-07-08 8 views
0

私はTextInputLayoutの要素を持つレイアウトを持っており、文字のカウンターを有効にしたいと思います。問題はそれが動作していないと私はアプリを実行すると、カウンタが表示されません。あなたが見ることができるようにTextInputLayout setCounterEnablesが機能しません - Android

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/colorBackground" 
    android:paddingLeft="@dimen/create_step_padding" 
    android:paddingRight="@dimen/create_step_padding" 
    android:paddingTop="@dimen/create_step_padding"> 

    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <!-- Shipper Text Area--> 
     <android.support.design.widget.TextInputLayout 
      android:id="@+id/shipper_layout" 
      android:layout_width="0dp" 
      android:layout_height="110dp" 
      android:background="@drawable/text_area_background" 
      android:paddingEnd="@dimen/text_input_layout_side_padding" 
      android:paddingStart="@dimen/text_input_layout_side_padding" 
      android:paddingTop="@dimen/text_input_layout_top_padding" 
      app:counterEnabled="true" 
      app:hintTextAppearance="@style/HintTextStyle" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent"> 

      <android.support.design.widget.TextInputEditText 
       android:id="@+id/shipper_field" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@null" 
       android:gravity="top|start" 
       android:hint="@string/shipper_field" 
       android:inputType="textMultiLine" 
       android:lines="5" 
       android:overScrollMode="always" 
       android:scrollbarStyle="insideInset" 
       android:scrollbars="vertical" /> 
     </android.support.design.widget.TextInputLayout> 


     <!-- Consignee Text Area--> 
     <android.support.design.widget.TextInputLayout 
      android:id="@+id/consignee_layout" 
      android:layout_width="0dp" 
      android:layout_height="110dp" 
      android:layout_marginTop="16dp" 
      android:background="@drawable/text_area_background" 
      android:paddingLeft="@dimen/text_input_layout_side_padding" 
      android:paddingTop="@dimen/text_input_layout_top_padding" 
      app:counterEnabled="true" 
      app:hintTextAppearance="@style/HintTextStyle" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/shipper_layout"> 

      <android.support.design.widget.TextInputEditText 
       android:id="@+id/consignee_field" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@null" 
       android:gravity="top|start" 
       android:hint="@string/consignee_field" 
       android:inputType="textMultiLine" 
       android:lines="5" 
       android:overScrollMode="always" 
       android:scrollbarStyle="insideInset" 
       android:scrollbars="vertical" /> 
     </android.support.design.widget.TextInputLayout> 

     <!-- Airport of Departure --> 

     <!-- Airport of Destination --> 

     <com.silverfix.dgdeditor.utils.views.AirportAutoCompleteEditText 
      android:id="@+id/aodep_field" 
      android:layout_width="217dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      android:layout_marginStart="8dp" 
      android:ems="10" 
      android:inputType="textPersonName" 
      android:text="Name" 
      app:layout_constraintBottom_toBottomOf="@+id/textView11" 
      app:layout_constraintHorizontal_bias="0.512" 
      app:layout_constraintLeft_toRightOf="@+id/textView11" 
      app:layout_constraintRight_toRightOf="parent" /> 

     <com.silverfix.dgdeditor.utils.views.AirportAutoCompleteEditText 
      android:id="@+id/aodes_field" 
      android:layout_width="217dp" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:inputType="textPersonName" 
      android:text="Name" 
      app:layout_constraintBottom_toBottomOf="@+id/textView12" 
      app:layout_constraintLeft_toLeftOf="@+id/aodep_field" /> 

     <TextView 
      android:id="@+id/textView11" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      android:layout_marginStart="8dp" 
      android:layout_marginTop="32dp" 
      android:text="@string/aodep_field" 
      android:textAppearance="@style/DefaultTextStyle" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/consignee_layout" /> 

     <TextView 
      android:id="@+id/textView12" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="24dp" 
      android:text="@string/aodes_field" 
      android:textAppearance="@style/DefaultTextStyle" 
      app:layout_constraintLeft_toLeftOf="@+id/textView11" 
      app:layout_constraintTop_toBottomOf="@+id/textView11" /> 
    </android.support.constraint.ConstraintLayout> 
</ScrollView> 

が、私はTextInputLayout秒でapp:counterEnabledを有効に:

は、ここに私のレイアウトです。 次に、コード内に最大の文字を設定しようとします。ここで

コードです:

shipperTextArea = (TextInputLayout) rootView.findViewById(R.id.shipper_layout); 
consigneeTextArea = (TextInputLayout) rootView.findViewById(R.id.consignee_layout); 

shipperTextArea.setCounterMaxLength(60); 
consigneeTextArea.setCounterMaxLength(60); 

答えて

0

ちょうどこれを追加し、xmlファイルにカウンタを設定します。

<android.support.design.widget.TextInputLayout 
    app:counterMaxLength="60" 
    app:counterEnabled="true" 

私は、Javaクラスに設定する必要はありませんと思います。

関連する問題