我正在将 TextView
添加到具有属性 android:textisselectable
的 float 窗口。
mWindowManager.addView(textView, params);
除长按无法复制文本外,一切正常。奇怪的是,它在 Galaxy Tab 中运行良好,但在我拥有的任何其他 5 英寸手机上却不行。
最佳答案
我认为是版本问题。 Galaxy Tab 的版本高于 Honeycomb,而 5 英寸屏幕可能是 Honeycomb 或更低版本。
试试这段代码:
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);
}
关于android:textisselectable 在 TYPE_SYSTEM_ALERT 窗口中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33724194/