【问题标题】:Why doesn't this simple code work without " android:textIsSelectable="true" "?为什么没有“ android:textIsSelectable="true" ”这个简单的代码不能工作?
【发布时间】: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


【解决方案1】:
android:textIsSelectable

已在API> 11中添加,因此您不能在API

Doc.

【讨论】:

  • 你确定吗?我们无法在 API 11 之前的 textView 中选择文本??
  • 所以这段代码没用??????因为如果你只添加“android:textIsSelectable”你可以复制到剪贴板.....
  • 如果您愿意,可以将它用于最新的 android 版本
猜你喜欢
  • 2015-07-31
  • 1970-01-01
  • 1970-01-01
  • 2013-05-04
  • 2012-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
相关资源
最近更新 更多