JUNS
JUNS

Reputation: 167

Custom Alertdialog In Android Kotlin

I've tried to change the color of text and background in Alertdialog to white text and transparent background. However, it didn't work.

Please refer to below and let me know what did I miss. Thank you.

Note: Android with Kotlin

*** 1. Code in Main Activity *** enter image description here

*** 2. Style.xml ***

enter image description here

*** 3. Simulation Outcome *** enter image description here

*** 4. What I want to is *** enter image description here

Upvotes: 1

Views: 254

Answers (2)

Dinesh
Dinesh

Reputation: 1670

For transparent dialog, you need to set android:background change your style like

<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:background">@android:color/transparent</item>
</style>

UPDATE

<style name="myAlertdialogstyle" parent="Theme.AppCompat.Light.Dialog.Alert">
       <item name="android:windowBackground">@android:color/transparent</item> 
       <item name="android:textColorPrimary">@android:color/white</item> 
       <item name="android:textColor">@android:color/white</item>
 </style> 

Upvotes: 1

alokHarman
alokHarman

Reputation: 289

<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="android:background">@color/Black</item> <item name="colorAccent">@color/White</item> </style> Here android:Background is android property so it will automatically reflect to your dialog also you should use Theme.AppCompat.Light.Dialog.Alert instead of Theme.AppCompat.Light.Dialog

Upvotes: 1

Related Questions