I'm trying to change the background color of an Android AlertDialog.
Every post I've seen is about changing the color of the AlertDialog, but not the background behind.
Any help would be appreciated.
I'm trying to change the background color of an Android AlertDialog.
Every post I've seen is about changing the color of the AlertDialog, but not the background behind.
Any help would be appreciated.
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:background">@color/myColor</item>
and then apply it in the Builder constructor:
AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.MyDialogTheme)
...
.create();
for more info see see this post
you can reduce the dim Amount
dialog.getWindow().setDimAmount(0.5f);
To get a background color you need to make a custom Alert Dialog.
There is one way to do what you asked for but its not that much of a good solution
First, set custom dialog theme like this.
styles.xml
<style name="CustomDialogTheme" parent="android:Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
CustomDialog.java
Apply the theme and construct your custom_dialog view as follows.
public HTCustomDialog(Context context) {
super(context, R.style.CustomDialogTheme);
setContentView(R.layout.custom_dialog);
}
custom_dialog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/main_solid_80">
<RelativeLayout
android:id="@+id/dialog_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@drawable/bg_popup"
android:padding="16dp">
</RelativeLayout>
Now that CustomDialog view is a full-screen view, set background of your root layout to whatever color you'd like.
I got this answer from here take a look .