2016-09-10 6 views
13

私は入力フィールドのためのそのきちんとしたフローラベル効果を達成するために、私のAndroidアプリでTextInputLayoutを使用しています。私は、TextInputEditTextを使用して、風景モードで入力が画面全体を塗りつぶすときにヒントを表示できるようにするべきであることを知っています。TextInputLayoutとAutoCompleteTextView

しかし、私の入力フィールドの一部に私がAutoCompleteTextView使用に行く自動補完を持っている( - 代わりに「のEditText」の「のTextViewを」 - IMOはそれに本当に一貫性のない名前を持っているが、それはまた別の話だ)、それは明らかに直接継承しますEditTextから。したがって、TextInputEditTextと同じ機能を持ちません。

同じヒント・イン・ランドスケープ機能を実現する方法があるかどうかは疑問です。これは、私自身のTextInputAutoCompleteTextViewの実装を行わずに行うこともできます。私はここに何かを逃していますか私は、この特定の事のためにEditTextのすべての直接的および間接的なサブクラスのカスタムバージョンを作成していないと思うので、私は自分自身を作ることを期待していますか?

答えて

12

少し遅れますが、はい、独自の実装をロールバックする必要があります。良いニュースは、これはかなり簡単だということです。ここでは、そのため

https://android.googlesource.com/platform/frameworks/support.git/+/master/design/src/android/support/design/widget/TextInputEditText.java

TextInputAutoCompleteTextViewがどのように見えるかです:ここではTextInputEditTextが実施された方法です。

public class TextInputAutoCompleteTextView extends AppCompatAutoCompleteTextView { 

    public TextInputAutoCompleteTextView(Context context) { 
     super(context); 
    } 

    public TextInputAutoCompleteTextView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public TextInputAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

    @Override 
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) { 
     final InputConnection ic = super.onCreateInputConnection(outAttrs); 
     if (ic != null && outAttrs.hintText == null) { 
      // If we don't have a hint and our parent is a TextInputLayout, use it's hint for the 
      // EditorInfo. This allows us to display a hint in 'extract mode'. 
      final ViewParent parent = getParent(); 
      if (parent instanceof TextInputLayout) { 
       outAttrs.hintText = ((TextInputLayout) parent).getHint(); 
      } 
     } 
     return ic; 
    } 
} 
+0

決して遅すぎず、私の友人!ええ、私は思ったほどです。私は、TextInputEditTextは非常に単純なので、本当に問題ではないと思う。お返事をありがとうございます! ☺ – sindrenm