【发布时间】:2014-04-01 07:59:32
【问题描述】:
我有这段代码用于从TextView 复制到剪贴板,但如果您不添加android:textIsSelectable="true",则此代码不起作用。为什么?
我的意思是,如果您不使用此代码而仅添加 android:textIsSelectable="true" 您可以将 TextView 复制到剪贴板但在 API >=11 中,因此当我将此代码用于 API
txt=(TextView)findViewById(R.id.txt);
final int startIndex = txt.getSelectionStart();
final int endIndex = txt.getSelectionEnd();
final String stringYouExtracted = txt.getText().toString().substring(startIndex, endIndex);
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(stringYouExtracted);
【问题讨论】:
-
你应该接受我的回答,以避免让这个问题没有答案。我写这个是因为从你上一个答案中你明白我在答案中写了什么。
标签: android textview clipboard selectable