2017-04-04 4 views
-2

TextInputLayoutを使用して必須フィールドを作成しようとしています。 Spannableクラスを使用しましたが、TextInputLayoutのヒントを単一のcolor.Iで表示しました。私のビューは、下のリンクのように見えます。赤いアリスマークでTextInputLayoutを作成する方法

https://material.io/guidelines/components/text-fields.html#text-fields-search-filter

+0

申し訳ありませんが、これはStackOverflowのが動作する方法はありません。 "私はXをしたい、私にヒントやサンプルコードを教えてください"という形式の質問は、話題とはみなされません。 [ヘルプセンター](http://stackoverflow.com/help)にアクセスし、[How to Ask](http://stackoverflow.com/help/how-to-ask)を読んでください。特に[Why is [誰かが私を助けることができますか?」実際の質問ではありませんか?](http://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) – bc004346

答えて

0

私はマテリアルデザインのテキストフィールドにできるだけ似ているために、次のTextInputEditTextを作成しました。

XMLレイアウト

  <android.support.design.widget.TextInputLayout 
      android:id="@+id/etlayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:counterEnabled="true" 
      app:counterMaxLength="25"> 

      <android.support.design.widget.TextInputEditText 
       android:id="@+id/et" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:paddingTop="16dp" 
       android:layout_marginLeft="-4dp" 
       android:layout_marginStart="-4dp" 
       android:layout_marginTop="8dp" 
       android:textSize="16sp" 
       android:inputType="text|textCapSentences" 
       android:singleLine="true" 
       android:hint="@string/title" 
       android:textColorHint="@color/transparent38"/> 

     </android.support.design.widget.TextInputLayout> 

<color name="transparent38">#66000000</color> 

のJava

etlayout = (TextInputLayout)findviewbyid(R.id.etlayout); 

     TextWatcher twTitle = new TextWatcher() { //Analyzes when the view changes 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 
       if (true) { //Replace condition with validity test 
       etlayout.setErrorEnabled(false); //Removes the extra space 
       etlayout.setError(null); //Removes the error message 
      } else { //If the text is not valid 
       etlayout.setErrorEnabled(true); //Makes the space for the error appear 
       etlayout.setError("Invalid input"); //Shows a message 
      } 
      } 

      @Override 
      public void afterTextChanged(Editable s) { 

      } 
     }; 
     etTitle.addTextChangedListener(twTitle); 
関連する問題