EditText textAllCaps 不适用于 textIsSelectable

j2e*_*esu 5 android android-layout

我的布局中有一个 TextView:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAllCaps="true"
    android:text="Hello"
    />
Run Code Online (Sandbox Code Playgroud)

textAllCaps 效果很好,没问题。但是当我尝试通过添加 textIsSelectable 使文本可选时

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAllCaps="true"
    android:textIsSelectable="true"
    android:text="Hello"
    />
Run Code Online (Sandbox Code Playgroud)

textAllCaps 不起作用。似乎这两个属性不能正常工作。您有什么建议为什么会发生这种情况以及如何使文本全部大写和可选择(我对最清晰的方式感兴趣,而不是手动设置文本更改侦听器和大写文本)。我将不胜感激任何建议,谢谢。

Log*_*gic 6

你可以试试这个Activity

edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()});


j2e*_*esu 2

我找到了一个解决方案。这是使用AppCompatTextViewapp:textAllCaps

<android.support.v7.widget.AppCompatTextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:textAllCaps="true"
    android:textIsSelectable="true"
    android:text="Hello"
    />
Run Code Online (Sandbox Code Playgroud)

我不确定这是最好的解决方案(AppCompatTextView文档告诉您仅在创建自定义组件时才使用此组件),但它有效。