简体   繁体   中英

Not able to select text in Edittext in Android on longclick?

I am trying to select text in Edittext for showing options of copy,paste but it is not selecting text on long press.

 <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>

I am using Android studio and build tools version 21.1.2.

You just need to set the color of highlighting background color.

Add this: android:textColorHighlight="@android:color/holo_red_dark"

<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" />

Your code is working in my phone i am using micromax untie 2.

You have hint in you edittext so its showing hint not text, Are you testing without typing anything into editText if that so then its just a hint and on doing long press on hint it will just show a paste option or may be dont show anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM