Search code examples
javaandroidxmlandroid-serviceautocompletetextview

AutoCompleteTextView can't copy/paste in a service


I have an AutoCompleteTextView in a floating service. In java:

final AutoCompleteTextView editText = mFloatingView.findViewById(R.id.text_box);
editText.setFocusableInTouchMode(true);
editText.requestFocus();

In xml:

        <AutoCompleteTextView android:id="@+id/link"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textColor="@color/text"
            android:selectAllOnFocus="true"
            android:completionThreshold="1"
            android:singleLine="true"
            android:imeOptions="actionSearch"
            android:inputType="textNoSuggestions|textWebEditText"
            android:background="@null">
        </AutoCompleteTextView>

enter image description here The problem:

-the two handles do not appear

-the copy and paste buttons do not appear


Solution

  • To enable the standard copy/paste for TextView, try this :

    android:textIsSelectable="true"
    

    Also, if your app theme extends a .NoActionBar theme, you need to enable windowActionModeOverlay:

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionModeOverlay">true</item>
    </style>