Search code examples
androidandroid-viewandroid-theme

EditText selected text range pointer got strange background


EditText style

    <style name="MyEditTextStyle" parent="Widget.AppCompat.EditText">
            <item name="android:textCursorDrawable">@null</item>
            <item name="android:textColor">@color/color_states_blackish</item>
            <item name="android:fontFamily">@font/sfd_medium</item>
            <item name="android:background">@drawable/edit_white_gray_x_normal_rounded</item>
            <item name="android:height">@dimen/general_view_height</item>
        </style>

Dialog style

 <style name="MyAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
        <item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
    </style>
    <style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
        <item name="android:textColor">@color/text_color_blackish</item>
        <item name="android:fontFamily">@font/sfd_regular</item>
    </style>

    <style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
        <item name="android:textColor">@color/text_color_blackish</item>
        <item name="android:fontFamily">@font/sfd_bold</item>
    </style>

Dialog code

final EditText editText = new EditText(new android.view.ContextThemeWrapper(getContext(),R.style.MyEditTextStyle));
                        final FrameLayout layout = new FrameLayout(getContext());
                        int padding = getContext().getResources().getDimensionPixelSize(R.dimen.standard_wall_space);
                        int paddingView = getContext().getResources().getDimensionPixelSize(R.dimen.standard_view_space);
                        layout.setPadding(padding,paddingView,padding,paddingView);
                        layout.addView(editText);
                        editText.setHint(R.string.type_here);
                        new AlertDialog.Builder(getContext(),R.style.MyAlertDialogTheme)
                        .setTitle("Enter Your Unit")
                        .setView(layout)
                        .setPositiveButton("Add", (dialog, whichButton) -> {
                            String value = editText.getText().toString();
                            MyApp.showToast("Unit-"+value);
                        })
                        .setNegativeButton("Cancel", null).show();

What I got following kind of pointers with background same as EditText, I remove them ContextThemeWrapper then It shows correctly but I need change the background using style?, Why is this happening? This is dialog inside fullscreen dialog? Any solution? Thanks

enter image description here


Solution

  • Looks like bugg, selector popup window get wrong background style, Don't use ContextThemeWrapper, style then it shows normally, set background programmatically.

     final EditText editText = new EditText(getContext());
    editText.setBackgroundResource(R.drawable.edit_white_gray_x_normal_rounded);
    editText.setTextColor(ContextCompat.getColor(getContext(),R.color.color_states_blackish));