Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoCompleteTextView weird cropping issue on cut/copy/paste menu when onLongClick

I have a problem on showing cut/copy/paste menu. After you've written a String in AutoCompleteTextView, in the first selection (LongClick) of the word opening cut/copy/paste menu. Unfortunately this menu is dislocated from its original place. This is the result when longClicked on the word. It's impossible to select any actions on it.

The interesting thing is when I click on the left and right selection indicators to change the range of the word, cut/copy/paste menu renders itself and correct its position. And now its possible to click on cut/paste/copy action buttons. This is the result when renders itself in correct position and no cropping issue stays on the screen

I've tried to change everything to find what is causing this problem but nothing is changed. I think something triggers android's default cut/copy/paste menu in wrong position with cropping. Unfortunately I can't find what it is.

Any advice is appreciated. Thanks.


The things may occur this problem:

  • In AndroidManifest.xml -> in related activity, "android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
  • In AndroidManifest.xml -> in related activity, "android:theme=@style/customTheme"
  • In AndroidManifest.xml -> in related activity, android:windowSoftInputMode="adjustPan"
  • In MyDialogFragment.java -> while setting up the actionBar

 AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example"
    android:installLocation="auto">


    <uses-permission android:name="com.example.permission.C2D_MESSAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.CAMERA" /> 
    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />

    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />


    <application
          android:name="com.example.MainApplication"
          android:hardwareAccelerated="true"
          android:icon="@drawable/icon"
          android:label="@string/app_name"
          android:largeHeap="true"
          android:theme="@style/ExampleTheme">


        <activity
            android:name="com.example.MainActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:launchMode="singleTask"
            android:screenOrientation="sensorPortrait"
            android:theme="@style/ExampleTheme"
            android:windowSoftInputMode="adjustPan" />

        <activity
            android:name="com.example.SplashScreen"
            android:launchMode="singleTop"
            android:screenOrientation="sensorPortrait"
            android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>



    </application>


</manifest>

themes.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="ExampleTheme" parent="Theme.AppCompat.Light">
        <item name="android:editTextStyle">@style/Widget.EditText</item>
        <item name="android:windowBackground">@color/app_bg</item>
        <item name="android:listViewStyle">@style/TransparentListView</item>
        <item name="buttonStyle">@style/ButtonStyle</item>
        <item name="android:alertDialogStyle">@style/customDialogTheme</item>
        <item name="android:alertDialogTheme">@style/customDialogTheme</item>
        <item name="android:expandableListViewStyle">@style/TransparentExpandableListView</item>
        <item name="android:spinnerStyle">@style/CustomSpinnerStyle</item>
        <item name="android:dropDownSpinnerStyle">@style/CustomSpinnerStyle</item>
    </style>

    <style name="ButtonStyle" parent="Widget.AppCompat.Button">
        <item name="android:textAllCaps">false</item>
    </style>

    <style name="Widget.EditText" parent="@android:style/Widget.EditText">
        <item name="android:background">@drawable/input_area</item>
    </style>

    <style name="TransparentListView" parent="@android:style/Widget.ListView">
        <item name="android:cacheColorHint">@color/transparent</item>
    </style>

    <style name="TransparentExpandableListView" parent="@android:style/Widget.ExpandableListView">
        <item name="android:cacheColorHint">@color/transparent</item>
    </style>

    <style name="customDialogTheme" parent="android:Theme.Holo.Light.Dialog.NoActionBar">
        <item name="android:windowBackground">@color/transparent</item>
        <item name="android:background">@color/transparent</item>
    </style>

    <style name="DialogFullScreenTheme" parent="android:Theme.Dialog">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">match_parent</item>
        <item name="android:windowAnimationStyle">@style/BlurDialogAnimation</item>

        <!-- No backgrounds, titles or window float -->
        <item name="android:windowBackground">@null</item>
        <item name="android:gravity">center</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">false</item>
    </style>
    <style name="BlurDialogAnimation">
        <item name="android:windowEnterAnimation">@anim/fadein</item>
        <item name="android:windowExitAnimation">@anim/fadeout</item>
    </style>

    <style name="DialogFullScreenThemeHolo" parent="android:Theme.Holo.Light.Dialog">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">fill_parent</item>
        <item name="android:windowAnimationStyle">@style/BlurDialogAnimation</item>

        <!-- No backgrounds, titles or window float -->
        <item name="android:gravity">center</item>
        <item name="android:windowBackground">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">false</item>
    </style>

    <!-- Overwrite the ToggleButton style -->
    <style name="Widget.Button.Toggle" parent="android:Widget">
        <item name="android:background">@drawable/btn_toggle_bg</item>
        <item name="android:textOn">ON</item>
        <item name="android:textOff">OFF</item>
        <item name="android:disabledAlpha">?android:attr/disabledAlpha</item>
    </style>

</resources>

MyDialogFragment.java: 

public class MyDialogFragment extends DialogFragment{
    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog d = new Dialog(getActivityInstance(), R.style.DialogFullScreenTheme);
        d.setContentView(R.layout.search_dialog_fragment);
        actionSearchBarET = (AutoCompleteTextView) d.findViewById(R.id.actionSearchBoxACT);
        actionBar = (RelativeLayout) d.findViewById(R.id.actionBar);
        setupSearchBar();
        actionSearchBarET.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
            InputMethodManager imm = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
            } catch (Exception ignored) {}
        }
        });
        actionSearchBarET.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionSearchBarET != null && actionSearchBarET.getText() != null && !actionSearchBarET.getText().toString().equalsIgnoreCase("")) {
                    searchWithKeyword(actionSearchBarET.getText().toString());
                }
                return true;
            }
        });
    }

    private void setupSearchBar() {
        TypedValue tv = new TypedValue();
        RelativeLayout.LayoutParams actionBarParams;
        if(getActivityInstance().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            int actionBarHeight = TypedValue.complexToDimensionPixelOffset(tv.data,     getActivityInstance().getResources().getDisplayMetrics());
            if(actionBarHeight > 0) {
                actionBarParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,  actionBarHeight);
            } else {
                actionBarParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,  getActivityInstance().getResources().getDimensionPixelOffset(   R.dimen.action_bar_default_height));
            }
        } else {
            actionBarParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,  getActivityInstance().getResources().getDimensionPixelOffset(R.dimen.action_bar_default_height));
        }
        actionBar.setMinimumHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,     getResources().getDimension(R.dimen.action_bar_default_height), getResources().getDisplayMetrics()));
        actionBar.setLayoutParams(actionBarParams);

    }
}

search_dialog_fragment.xml:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/white"
    android:paddingBottom="15dp">

    <include
            android:id="@+id/actionBar"
            android:layout_alignParentTop="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/ab_search_and_textbutton" />

</RelativeLayout>

ab_search_and_textbutton.xml: 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:paddingLeft="15dp">

    <!-- Dummy item to prevent EditText from receiving focus -->
    <LinearLayout
        android:id="@+id/dummy"
        android:layout_width="0dip"
        android:layout_height="0dip"
        android:focusable="true"
        android:layout_alignParentRight="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"/>

    <RelativeLayout
        android:id="@+id/searchBarContainer"
        android:layout_centerVertical="true"
        android:minHeight="@dimen/searchbar_height"
        android:background="@drawable/search_box_bg"
        android:layout_gravity="center"
        android:layout_toLeftOf="@+id/cancelButton"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/searchbar_height">

        <ImageView
            android:id="@+id/searchIcon"
            android:layout_marginLeft="15dp"
            android:layout_centerVertical="true"
            android:src="@drawable/search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <AutoCompleteTextView
            android:layout_toRightOf="@+id/searchIcon"
            android:layout_marginLeft="3dp"
            android:id="@+id/actionSearchBoxACT"
            android:textSize="14dp"
            android:inputType="textNoSuggestions"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="@string/search"
            android:focusableInTouchMode="true"
            android:focusable="true"
            android:textColor="@color/textcolor_black"
            android:layout_centerInParent="true"
            android:background="@null"
            android:completionThreshold="1"
            android:imeOptions="actionSearch"
            android:nextFocusLeft="@id/actionSearchBoxACT"
            android:nextFocusUp="@id/actionSearchBoxACT"
            android:paddingLeft="5dp"
            android:singleLine="true">
            <requestFocus />
        </AutoCompleteTextView>


    </RelativeLayout>


</RelativeLayout>
like image 215
Orcun Sevsay Avatar asked Nov 07 '22 11:11

Orcun Sevsay


1 Answers

Probably, cut/paste/copy menu is affected by your theme xml. DialogFullScreenTheme style contains gravity field. You may remove that field but you must check all dialogs ui.

<style name="DialogFullScreenTheme" parent="android:Theme.Dialog">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">match_parent</item>
        <item name="android:windowAnimationStyle">@style/BlurDialogAnimation</item>
        <item name="android:windowBackground">@null</item>

        <!-- Remove this line -->
        <item name="android:gravity">center</item>

        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">false</item>
    </style>
like image 54
Bahadır Bulduk Avatar answered Nov 15 '22 11:11

Bahadır Bulduk