更改文本输入布局中的文本提示样式



当编辑文本集中时,我想将提示文本样式更改为大写。当注意力不集中时,保持正常。仅使用xml

<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="@style/MyFilledBox"
android:inputType="textCapWords"
android:hint="test app"
app:endIconMode="password_toggle"
app:endIconTint="@color/black">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="true"/>
</com.google.android.material.textfield.TextInputLayout>[![enter image description here][1]][1]

您需要使用;setOnFocusChangeListener";我们的EditText 方法

mEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (!hasFocus) {
mInputLayout.setHint("un capitalize hint"")
}else {
mInputLayout.setHint("CAPITALIZE HINT"")
}
}
});

最新更新