When we use Theme.AppCompat.DayNight on android , we may want to customise alert dialog window background , text and buttons color .Just define a seperate style for alert dialog in your style xml like below .
<style name="CustomDialogStyle" parent="Theme.AppCompat.DayNight.Dialog.Alert">
    <!-- buttons -->
    <item name="colorAccent">#00FF00</item>
    <!-- title and text -->
    <item name="android:textColorPrimary">#000000</item>
    <!-- background you can change some other color than white -->
    <item name="android:background">#FFFFFF</item>
     <!-- change if you want below -->
    <item name="android:textColor">@null</item>
    <item name="android:textSize">@null</item>
</style>
and then call it like
AlertDialog dialog =
        new AlertDialog.Builder(this, R.style.CustomDialogStyle)
For style.xml(night) you can define different style like below
<style name="CustomDialogStyle" parent="Theme.AppCompat.DayNight.Dialog.Alert">
    <!-- buttons -->
    <item name="colorAccent">#00FF00</item>
    <!-- title and text -->
    <item name="android:textColorPrimary">#FFFFFF</item>
    <!-- background you can change to some other color than black-->
    <item name="android:background">#000000</item>
     <!-- change if you want below -->
    <item name="android:textColor">@null</item>
    <item name="android:textSize">@null</item>
</style>

0 Comments