无法在Android的长单击中选择Edittext中的文本?

无法在Android的长单击中选择Edittext中的文本?,android,android-layout,android-activity,Android,Android Layout,Android Activity,我试图在Edittext中选择文本以显示复制、粘贴选项,但它并没有在长按时选择文本 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padd

我试图在Edittext中选择文本以显示复制、粘贴选项,但它并没有在长按时选择文本

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">

<EditText
    android:id="@+id/et_extractedText"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textIsSelectable="true"
    android:layout_gravity="top|center"
    android:gravity="start"
    android:hint="@string/st_etHint"
    android:inputType="textMultiLine"
    android:scrollbars="vertical"
    android:typeface="monospace" />

    </FrameLayout>

我使用的是Android studio和构建工具版本21.1.2。

您的代码在我的手机中正常工作。我使用的是micromax Unite 2


您的edittext中有提示,所以它是显示提示而不是文本,您是否在测试时没有在edittext中键入任何内容如果是这样,那么它只是一个提示,在执行长按提示时,它将只显示粘贴选项,或者可能是不显示任何内容。

您的代码在我的手机中工作我正在使用micromax Unte 2


您在edittext中有提示,所以它是显示提示而不是文本,您是否在测试时没有在edittext中键入任何内容?如果是这样,那么它只是一个提示,在执行长按提示操作时,它将只显示粘贴选项或可能不显示任何内容。

您只需要设置突出显示背景色的颜色

添加:android:textColorHighlight=@android:color/holo\u red\u dark


您只需要设置高亮显示背景色的颜色

添加:android:textColorHighlight=@android:color/holo\u red\u dark



猜猜看,删除这一行:android:textIsSelectable=true,通常edittext在默认情况下是长时间可点击的。我删除了android:textIsSelectable=true,但仍然不工作抱歉,我的手机上的即时通讯无法真正测试任何东西;try:android:longClickable=true,但据我所知,默认情况下它通常为true。@DanishZia您的代码在moto G2中运行良好,正如我所测试的,您能解释一下在书面文本或其他地方使用longpress是指longpress吗?我在文本上使用longpress。猜测一下,删除这一行:android:textIsSelectable=true,通常edittext在默认情况下是长时间可点击的。我删除了android:textIsSelectable=true,但仍然不工作抱歉,我的手机上的Im无法真正测试任何东西;try:android:longClickable=true,但据我所知,默认情况下它通常为true。@DanishZia您的代码在moto G2中运行良好,正如我所测试的,您能解释一下在什么地方使用longpress是指在书面文本上使用longpress还是在其他地方使用longpress吗?我正在对文本进行longpress。我正在输入它,这可能是因为我正在使用??因为我以前总是这样。在键入edittext后,您是在空白区域长按还是在键入的文本上长按?因为若你们一直在空的区域上按下按钮,那个么它将不会做任何事情。您必须长按您在edittext字段中输入的文本。我长按文本。请删除“android:inputType=textMultiLine”并添加“android:singleLine=true”,然后检查单行edittext是否进行选择。我正在输入文本,这可能是因为我正在使用??因为我以前总是这样。在键入edittext后,您是在空白区域长按还是在键入的文本上长按?因为若你们一直在空的区域上按下按钮,那个么它将不会做任何事情。您必须长按在edittext字段中输入的文本。我长按文本。请删除“android:inputType=textMultiLine”并添加“android:singleLine=true”,然后检查单行edittext是否进行选择。
<EditText
    android:id="@+id/et_extractedText"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textIsSelectable="true"
    android:layout_gravity="top|center"
    android:gravity="start"
    android:hint="@string/st_etHint"
    android:inputType="textMultiLine"
    android:scrollbars="vertical"
    android:typeface="monospace"
    android:textColorHighlight="@android:color/holo_red_dark" />