By Wahib


2015-03-29 11:03:21 8 Comments

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.

2 comments

@Mohammad Elsayed 2020-08-01 13:50:13

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

@Pankaj 2015-03-29 11:38:18

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.

@Wahib 2015-03-29 11:42:59

i am typing into it, can it be because of the i am using ?? Because this always work for me before.

@Pankaj 2015-03-29 11:59:08

After typing in edittext are you doing long press in empty area or on the text you have typed? Because if you have long pressed on empty area then it would not do anything. You have to long press on text which you have inputed in edittext field.

@Wahib 2015-03-29 12:48:24

I am long pressing on the text.

@Pankaj 2015-03-29 13:06:58

Please remove 'android:inputType="textMultiLine"' and add 'android:singleLine="true"' and check it out whether single line edittext making selection or not.

Related Questions

Sponsored Content

106 Answered Questions

23 Answered Questions

[SOLVED] Is there a way to run Python on Android?

29 Answered Questions

[SOLVED] What is 'Context' on Android?

51 Answered Questions

[SOLVED] Is there a unique Android device ID?

53 Answered Questions

[SOLVED] How do I pass data between Activities in Android application?

20 Answered Questions

[SOLVED] What is the difference between gravity and layout_gravity in Android?

52 Answered Questions

33 Answered Questions

[SOLVED] Activity restart on rotation Android

11 Answered Questions

[SOLVED] Proper use cases for Android UserManager.isUserAGoat()?

Sponsored Content