Qamar
Qamar

Reputation: 5137

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

Upvotes: 1

Views: 171

Answers (3)

Zaif Senpai
Zaif Senpai

Reputation: 91

Additional to other answers here, it also occurs when we set background in the app theme in style.xml. Another solution I found was to replace android:background with android:backgroundTint of the background color and set android:backgroundTintMode to multiple.

Put this in styles:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <item name="android:backgroundTint">#FFFFFF</item>
    <item name="android:backgroundTintMode">multiply</item>
</style>

or in the view tag whose background color you want to change:

<View
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:backgroundTint="#FFFFFF"
    android:backgroundTintMode="multiply" />

Upvotes: 0

Qamar
Qamar

Reputation: 5137

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));

Upvotes: 1

algrid
algrid

Reputation: 5954

The problem is that the android:background parameter in your theme is applied to everything inside the EditText. For me the solution was in removing that parameter from the style.

Upvotes: 1

Related Questions