【问题标题】:how to NOT select all on EditText long click如何在 EditText 上长按不全选
【发布时间】:2013-05-05 03:25:42
【问题描述】:

当用户在 EditText 中长按/长按时,我的应用程序总是选择所有文本。你如何让 EditText not 全选,而是选择 only 用户选择的文本?

我读过Select all text inside EditText when it gets focus 然后尝试显式设置android:selectAllOnFocus="false",但这不起作用。双击或任何其他点击长度也不起作用。

override OnLongClickListener 可能有效,但我不知道如何获取用户的开始和结束选定索引。

【问题讨论】:

标签: android android-layout


【解决方案1】:

对于将来遇到此问题的人,(或至少一个)解决方案是将textLongMessage 选项添加到android:inputType

<EditText
    ...
    android:inputType="textLongMessage" >

<!-- Or you might have multiple input types -->
<EditText
    ...
    android:inputType="textLongMessage|textMultiLine|textNoSuggestions" >

这将使 EditText 的行为是从文本中选择一个单词。

【讨论】:

    【解决方案2】:

    尝试阅读这些链接,看看它们是否有帮助: how to NOT select all on EditText long click

    how to NOT select all on EditText long click

    You can try in your main.xml file:
    
    android:selectAllOnFocus="true"
    

    【讨论】:

    • 这怎么可能是一个答案?
    猜你喜欢
    • 2016-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-06
    • 1970-01-01
    相关资源
    最近更新 更多