android - 使用 TextInputLayout 时更改 EditText textAllCaps

标签 android

我正在使用设计库中的新 TextInputLayout。我能够让它显示并更改 float 标签的颜色。不幸的是,它不会将文本更改为大写。

我不想更改我的 strings.xml,因为我只希望这个标签是大写的。我尝试过更改布局、样式和编程方式中的 textAllCaps,但 EditText 提示的大小写始终与 strings.xml 完全相同。

这是我的 TextInputLayout 和 EditText 的 XML

<android.support.design.widget.TextInputLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android.support.design:hintTextAppearance="@style/TextInputLayout">


<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/city"
    android:textColorHint="@color/black"
    android:hint="@string/city" />

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

这是我为 TextInputLayout 使用的样式(我尝试使用唯一的“textAllCaps”(没有“android:”)属性,但没有为我做任何事情):

<style name="TextInputLayout" parent="@android:style/TextAppearance">
 <item name="android:textAllCaps">true</item>
</style>

最佳答案

解决方法和@Janvi差不多,不过是通过BindingAdapter解决的,可以用xml代替代码:

@BindingAdapter("android:hint")
fun setTextInputLayoutHint(textInputLayout: TextInputLayout, hint: CharSequence?) {
    textInputLayout.hint = hint?.toString()?.toUpperCase()
}

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/til_first_name"
        android:hint="@{@string/first_name}"

enter image description here

附言:

The hint should be set on TextInputLayout, rather than the TextInputEditText or EditText. https://material.io/develop/android/components/text-input-layout/

关于android - 使用 TextInputLayout 时更改 EditText textAllCaps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50139834/

相关文章:

android - 当我的 android 版本为 6+ 时,为什么 android/google play 要求我的 react native 应用程序的权限?

android - 工具提示内的 Bottom Sheet 无法正常工作,此弹出窗口显示在 Bottom Sheet 后面

android - 使用 Android 6.0 的 BluetoothLeScanner.startScan 无法发现设备

安卓蓝牙通知

php - Android/JSON : org. json.JSONException : Value of type java. lang.String 无法转换为 JSONObject

java - 无法解析方法 ParseDouble

Android:具体如何处理Back Press?

Android getLatitude() 返回大地纬度或地心纬度?

Android Thread postDelayed 不起作用

没有Facebook登录按钮的Android Facebook登录