Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText textAllCaps not working with textIsSelectable

I have a TextView in my layout:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAllCaps="true"
    android:text="Hello"
    />

textAllCaps works good, no problem. But when I try to make text selectable by adding textIsSelectable

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAllCaps="true"
    android:textIsSelectable="true"
    android:text="Hello"
    />

textAllCaps not working. It seems like these two attributes can't work together properly. Have you any suggestions why it happens and how to make text both all caps and selectable (I'm interested in a most clear way, not setting text change listener and capitalizing text manually). I'll be appreciate for any suggestions, thank you.

like image 356
j2esu Avatar asked Jan 27 '16 12:01

j2esu


2 Answers

Can you try this in Activity :

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

like image 188
Logic Avatar answered Oct 02 '22 06:10

Logic


I found one solution. It's to use AppCompatTextView and app: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"
    />

I'm not sure this is the best solution (AppCompatTextView docs tells to use this component only when creating custom components), but it works.

like image 40
j2esu Avatar answered Oct 02 '22 08:10

j2esu