Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to support textView.setTextIsSelectable in lower android versions?

textView.setTextIsSelectable(true);

requires min API level 11.

Is there anyway to support it from API level 8+ ?

like image 851
yajnesh Avatar asked Feb 10 '14 16:02

yajnesh


3 Answers

There are some methods described here & here, but there's probably no way to do this to achieve same functionality

like image 167
Sam Avatar answered Nov 15 '22 07:11

Sam


Create a new class by extending TextView class and override setTextIsSelectable

        @SuppressLint("NewApi")
public void setTextIsSelectable(boolean selectable) {
    if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB)
        super.setTextIsSelectable(true);
    else
    {   
        super.setLongClickable(true);
        super.setOnLongClickListener(getSelectableLongClick());
        super.setOnTouchListener(getSelectableOnTouch());
    }
}
like image 31
Vishal Vijay Avatar answered Nov 15 '22 05:11

Vishal Vijay


I'm using EditText with the attributes:

android:inputType="none"
android:background="@null"

And do this in code:

editText.setKeyListener(null);

Which makes EditText non-editable but still with select and copy functionality. The only drawback is the visible cursor when the widget is focused. I can't set android:cursorVisible to false because it hides the selection background together with the cursor.

like image 31
Viachaslau Tysianchuk Avatar answered Nov 15 '22 05:11

Viachaslau Tysianchuk