A
A
antihrust2021-08-03 15:18:28
Android
antihrust, 2021-08-03 15:18:28

How to change AlertDialog line color?

How to change linny color from pink to any other?

val dialog = AlertDialog.Builder(requireContext(), R.style.AlertTheme)
                .setTitle(getString(R.string.enter_problem_reason))
                .setView(reasonEditText)
                .setCancelable(true)
                .setPositiveButton(getString(R.string.ok)) { dialog, _ ->
                    onReasonGiven(reasonEditText.text.toString())
                    hideKeyboardFrom(requireContext(), reasonEditText)
                    dialog.cancel()
                }
                .setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
                    dialog.cancel()
                }
                .create()

        dialog.show()


Style:

<style name="AlertTheme" parent="Theme.AppCompat.Dialog.Alert">
        <item name="android:background">@color/color_gray_background</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:textColorPrimary">@color/white</item>
    </style>


61093410ce985992153090.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2021-08-04
@antihrust

I see that reasonEditText is used here, in which this color is pink by default.
Solution:
for example, I will create a reasonEditText programmatically, maybe you also create it either through markup, then you will need to set a backgroundTint and specify @drawable/bg_edittext in it

val reasonEditText = EditText(requireContext())
            reasonEditText.setBackgroundDrawable(requireContext().getDrawable(R.drawable.bg_edittext))

            val dialog = AlertDialog.Builder(requireContext(), R.style.AlertTheme)
                .setTitle("Причина приостановки подписки")
                .setView(reasonEditText)
                .setCancelable(true)
                .setPositiveButton("Ок") { dialog, _ ->
                    dialog.cancel()
                }
                .setNegativeButton("Отмена") { dialog, _ ->
                    dialog.cancel()
                }
                .create()

            dialog.show()

bg_edittext.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/transparent" />
        </shape>
    </item>

    <item
        android:left="-2dp"
        android:right="-2dp"
        android:top="-2dp">
        <shape>
            <solid android:color="@android:color/transparent" />
            <stroke
                android:width="1dp"
                android:color="@color/error_red" />
        </shape>
    </item>
</layer-list>

@color/error_red <- here you can use your own color to change the color of the line
610a791f8b18a232178152.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question