【问题标题】:make Android Textview or EditText selectable使 Android Textview 或 EditText 可选
【发布时间】:2015-02-19 11:51:58
【问题描述】:

我想在我的 android 项目中选择 EditTextTextview。 项目适用于 android 4.0+ 。我添加了这个:txtView.setTextIsSelectable(true) 和:txtView.setCustomSelectionActionModeCallback(new myCallback()); 制作我的自定义选择菜单。 但是当我想选择文本时发生了这个错误。

W/TextView﹕ TextView does not support text selection. Action mode cancelled.

我搜索了错误,但没有找到解决方案。我该怎么办?

【问题讨论】:

  • 检查你的 xml 中是否有 android:focusable="false" 或 android:focusableInTouchMode="false"
  • 看看这个:link
  • 你真正想要做什么..选择edittext和textview文本或在选择此小部件时显示颜色。
  • @Surenderkumar 我想让用户分享他们在 textview 中选择的文本。
  • @RafiduzzamanSonnet 谢谢,我试试看。

标签: android android-edittext textview selectable


【解决方案1】:
<TextView
    android:id="@+id/id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textIsSelectable="true"
    android:text="" />

*仅限 API 级别 11 及更高版本

【讨论】:

  • 你的好运@HAMED
  • textIsSelectable 放在我的 EditText 上会破坏 EditText 焦点,尤其是当您关闭键盘时(您永远无法再次打开它)。
  • 您可以提供任何解决方案@dextor,以便我可以编辑我的答案,
  • 好像只和EditText有关。所以不需要改变你的答案。
  • 真的有用吗?我也试过了。但是,它不起作用。尝试选择文本 W/TextView 时收到以下警告日志:TextView 不支持文本选择。动作模式已取消。
【解决方案2】:

setTextIsSelectable 确实解决了 Android 7.1.1 上的问题。 setEnabled(false) 然后 true 不起作用。

editText.setTextIsSelectable(true);

我的确切情况是设置了 setFocusable(false) 并添加了一个 onClickListener,然后设置 setFocusable(true) 和 onClickListener(null) 给了我 OP 中的错误。

(语法不正确,但你明白了)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-04
    • 2018-06-02
    • 2016-06-12
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    • 1970-01-01
    相关资源
    最近更新 更多