こんにちは、TextInputLayout のカスタム コンポーネントを作成しました。ヒントテキストをTextInputLayoutに設定したい。TextInputLayout をルート レイアウトに拡張するカスタム クラスを追加しています。私は次の方法でそれを試しました:
<android.support.design.widget.TextInputLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@color/gray"
android:theme="@style/editTextSelectedTheme"
android:layout_marginTop="@dimen/margin_10"
>
<EditText
android:id="@+id/form_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
public class FormEditText extends TextInputLayout
{
TextInputLayout view;
public FormEditText(Context context) {
super(context);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = (TextInputLayout)inflater.inflate(R.layout.form_edit_text, this, true);
initUI();
}
public FormEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FormEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
そして最後に私のフラグメントで:
FormEditText gadgetName = new FormEditText(getContext());
gadgetName.setHint(getResources().getString(R.string.gadget_name_hint));
formContainer.addView(gadgetName);
上記のコードは、ビューに新しい TextInputLayout を追加しますが、ヒント テキストを追加しません。私は何か間違ったことをしていますか?助けが要る。ありがとうございました。
以下のコメントに従って、いくつかの変更を加えました。
public class FormEditText extends LinearLayout
view = inflater.inflate(R.layout.form_edit_text, this, true);
必要に応じてヒント テキストが表示されるようになりましたが、編集テキスト値が表示されなくなりました。入力値を取得していません。