【问题标题】:textview textIsSelectable="true" not working in Listviewtextview textIsSelectable="true" 在 Listview 中不起作用
【发布时间】:2014-12-10 10:19:28
【问题描述】:
 <TextView
                    android:id="@+id/txtSender"
                    style="@android:style/TextAppearance.Small"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/sender_bubble"
                    android:gravity="center_vertical"
                    android:maxEms="11"
                    android:paddingBottom="5dp"
                    android:paddingLeft="5dp"
                    android:paddingRight="15dp"
                    android:paddingTop="5dp"
                    android:text="1234567"
                    android:autoLink="all"
                    android:textColor="@color/color_black"
                    android:textIsSelectable="true"
                    android:visibility="visible" />

这是我在 customcell 中的文本视图。当我单击 textview 时,它不允许我在 textview 中选择文本。它在我的 xperia 4.2.2 中运行完美,但是当我在 4.4.4 版本的设备中运行相同的代码时,它无法运行。

注意:当我将相同的 android:textIsSelectable="true" 属性设置为不在 Listview 中的 Textview 时,它在 4.4.4 中可以正常工作。 Listview 只需移动到底部并在半秒内重置到其原始位置。

【问题讨论】:

  • 尝试将此属性 android:focusable="false" android:focusableInTouchMode="false" 添加到您的文本视图中。
  • android:descendantFocusability="beforeDescendants" 在您的列表项 xml 中
  • @HareshChhelana :我已经尝试添加这两个属性,但它似乎不起作用
  • @MeenalSharma : android:descendantFocusability="beforeDescendants" 也不起作用
  • 参考以下链接,希望对您有所帮助。 stackoverflow.com/questions/15857755/…

标签: android listview textview


【解决方案1】:

在我的情况下它不起作用,因为我在带有 android:visibility="gone" 属性的 xml 布局中有 textView 并使其稍后在适配器代码中可见。因此,您需要在使 textview 可见后调用它

textView.setTextIsSelectable(true); 

【讨论】:

  • 它有效。然而,并不完全。看来您可以选择 TextView 的文本。但是,屏幕会调整大小,然后选定的块会立即消失。所以,它只是改变屏幕,就是这样。您可能需要阻止这种更改或其他操作。
【解决方案2】:

在recyclerview或listview中去掉android:descendantFocusability="blocksDescendants"​,防止选择被阻塞

另外,将 textview 布局宽度从 match_parent 更改为 wrap_content 以防止在重复使用文本单元格时禁用可选择文本功能。

【讨论】:

  • 我们正在使用android:descendantFocusability="blocksDescendants"。与 textIsSelectable 一起使用的 line 的替代方案是什么?
【解决方案3】:

删除 textIsSelectable,改为使用:

android:inputType="textMultiLine"

文本将是可选择和可编辑的。

【讨论】:

    猜你喜欢
    • 2016-07-07
    • 2019-04-16
    • 2021-10-17
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多