TextInputLayout
にラップされたEditText
を使用しています。 textSize
をEditText
に設定すると、入力テキスト自体に対してプログラム的に機能します。ただし、入力が空の場合に表示されるEditText
のヒントテキストには適用されません。TextInputLayout内のEditTextのヒントサイズをプログラムで設定します
ここに何か不足していますか、これはバグですか?後者の場合は、回避策がありますか?ここでは、説明するために
は、私のコードの抜粋です:カスタムView
内
TextInputLayout
:
<android.support.design.widget.TextInputLayout
android:id="@+id/password_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/default_password_hint"
android:textColorHint="@color/background_gray">
<EditText
android:id="@+id/txt_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
私は異なるテキストサイズでView
を再利用したいので、私は、カスタム属性を使用してテキストサイズを渡しますtextSize
:
<declare-styleable name="PasswordInputField">
<attr name="textSize" format="dimension"/>
<attr name="hint" format="string"/>
</declare-styleable>
と私のカスタムでそれを適用View
次のように:TextInputのレイアウトで
if (attrs != null)
{
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PasswordInputField, 0, 0);
try
{
String hint = ta.getString(R.styleable.PasswordInputField_hint);
if (hint != null)
{
passwordInputLayout.setHint(hint);
}
float textSize = ta.getDimensionPixelSize(R.styleable.PasswordInputField_textSize, 0);
if (textSize > 0)
{
passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
}
finally
{
ta.recycle();
}
}
こんにちは、これは、静的なシナリオのための適切な解決策であるようです。私のカスタムシナリオにカスタム属性を介して渡されるため、あなたのソリューションを私のシナリオに関連付けることができますか? –
このソリューションを試しましたか? –
申し訳ありませんが、プログラムでテキストサイズを設定する必要があります(カスタム表示/カスタムサイズとしてのテキストサイズの受け渡し)。だからあなたの静的な解決策が私の問題にどのように当てはまるのか分かりません。 –