Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:textisselectable not working in TYPE_SYSTEM_ALERT window

I am adding a TextView to a floating window which has attribute android:textisselectable.

mWindowManager.addView(textView, params);

Eveything is working fine except I cannot copy text on long press. The strange part is that it is working fine in Galaxy Tab but not on any other 5 inch phones I have.

like image 332
mihirjoshi Avatar asked Oct 30 '22 15:10

mihirjoshi


1 Answers

I think it's a version problem. The Galaxy Tab has a version more than Honeycomb whereas the 5 inches screen may be Honeycomb or lower.

Try this code:

TextView textView;
String stringToBeExtracted;
int startingIndex=textView.getSelectionStart();
int endingIndex=textView.getSelectionEnd();
stringToBeExtracted = stringYouExtracted.subString(startingIndex, endingIndex);
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setText(stringToBeExtracted);
} else {
    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    android.content.ClipData clip = android.content.ClipData.newPlainText("Text Copied", stringToBeExtracted);
            clipboard.setPrimaryClip(clip);
}
like image 169
Lips_coder Avatar answered Nov 11 '22 11:11

Lips_coder