pkgrover
pkgrover

Reputation: 305

how to enable editText cut/copy/paste functionality in android?

please don't mark this question as duplicate ,as this thing only working in one edittext which inputtype set as phone ,but it is not working in other edittext case here is my edittext that is working

<EditText
            android:layout_width="match_parent"
            android:layout_marginLeft="5dp"
            android:textColor="@android:color/background_dark"
            android:padding="@dimen/margin_15"
            android:textColorHint="@android:color/darker_gray"

            android:hint="Mobile Number"
            android:imeOptions="actionNext"
            android:inputType="phone"
            android:layout_height="wrap_content"
            android:background="@null"
            android:id="@+id/ed_phone"/> 

and one of other that s not working

<EditText
        android:layout_width="match_parent"
        android:layout_marginLeft="15dp"
        android:textColor="@android:color/background_dark"
        android:hint="@string/email"
        android:inputType="textEmailAddress"
        android:cursorVisible="true"
        android:imeOptions="actionNext"
        android:layout_height="wrap_content"
        android:textColorHint="@android:color/darker_gray"
        android:background="@android:color/transparent"
        android:id="@+id/ed_userName"/>

here is my App theme

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">#46C203</item>
        <item name="windowActionModeOverlay">true</item>
        <item name="android:windowActionModeOverlay">true</item>

    </style>

Now i have tried many ways to work this default copy/paste functioning, didn't find solution that worked for me Any help would be appreciable

Upvotes: 0

Views: 3586

Answers (4)

pkgrover
pkgrover

Reputation: 305

finally got the solution i was using this method for hiding my keyboard for touching outside editext

 @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        View view = getCurrentFocus();
        boolean ret = super.dispatchTouchEvent(event);

        if (view instanceof EditText) {
            View w = getCurrentFocus();
            int scrcoords[] = new int[2];
            w.getLocationOnScreen(scrcoords);
            float x = event.getRawX() + w.getLeft() - scrcoords[0];
            float y = event.getRawY() + w.getTop() - scrcoords[1];

            if (event.getAction() == MotionEvent.ACTION_UP
                    && (x < w.getLeft() || x >= w.getRight()
                    || y < w.getTop() || y > w.getBottom()) ) {

                ((EditText)view).setError(null);
                view.clearFocus();
                InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
            }
        }
        return ret;
    }

here i just need to comment this line

view.clearFocus();

and now it works

Upvotes: 1

Cochi
Cochi

Reputation: 2209

Can you try to add this attribute to your EditText :

 android:textIsSelectable="true"

Hope this helps.

Upvotes: 0

Rajshree Tiwari
Rajshree Tiwari

Reputation: 630

Add this line in your edit text :-

   android:textIsSelectable="true"

so your edittext will be like this :-

      <EditText
        android:layout_width="match_parent"
        android:layout_marginLeft="15dp"
        android:textColor="@android:color/background_dark"
        android:hint="mail"
        android:inputType="textEmailAddress"
        android:cursorVisible="true"
        android:imeOptions="actionNext"
        android:layout_height="wrap_content"
        android:textColorHint="@android:color/darker_gray"
        android:background="@android:color/transparent"
        android:id="@+id/ed_userName"
        android:textIsSelectable="true"/>

Hope it may help you . :)

Upvotes: 1

Darish
Darish

Reputation: 11481

The text you are trying to paste (from clipboard) should be a valid email address since you specified input type as email address, otherwise it would not work. all the best :)

Upvotes: 0

Related Questions