How to change the black color in Android dialogs or drawer menu -
in android, when show alert dialog, progress dialog, open drawer , etc, seems have transparent black layer on screen, kind of dialog, pic:
my goal changing transparent black layer, not background of dialog, see picture:
how change color of transparent black layer red or color? example in xml or code in java
this code myexitdialog class
public class myexitdialog extends dialog implements android.view.view.onclicklistener { databasehandler userdb; public activity c; public dialog d; public button yes, no; public myexitdialog(activity a) { super(a); this.c = a; } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.mydialog); yes = (button) findviewbyid(r.id.id_exit_yes); no = (button) findviewbyid(r.id.id_exit_no); yes.setonclicklistener(this); no.setonclicklistener(this); } @override public void onclick(view v) { switch (v.getid()) { case r.id.id_exit_yes: //c.finish(); draweractivity.userdb=new databasehandler(myexitdialog.this.getcontext()); draweractivity.userdb.open(); draweractivity.userdb.logout(); draweractivity.userdb.close(); draweractivity.changedraweritems("logout"); break; case r.id.id_exit_no: dismiss(); break; default: break; } dismiss(); } }
and how use that:
@override public boolean onnavigationitemselected(menuitem item) { // handle navigation view item clicks here. int id = item.getitemid(); fragment myfragment = null; view myview; typeface tf = typeface.createfromasset(getassets(), "fonts/byekan.ttf"); if (id == r.id.nav_home) { } else if (id == r.id.nav_register) { } else if (id == r.id.nav_change) { } else if (id == r.id.nav_login) { } else if (id == r.id.nav_factors) { } else if (id == r.id.nav_logout) { myexitdialog mydialog = new myexitdialog(draweractivity.this); mydialog.show(); } drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); drawer.closedrawer(gravitycompat.start); return true; }
for alertdialog, can set custom theme second parameter this.
alertdialog.builder dialog = new alertdialog.builder(context, r.style.customdialog);
and in style.xml set customdialog style
<resources> <style name="customdialog" parent="@style/theme.appcompat.light.dialog.alert"> <item name="android:background">@color/red</item> </style> </resources>
lastly, can set custom colour in colors.xml
<resources> <item name="blue" type="color">#ff33b5e5</item> <item name="purple" type="color">#ffaa66cc</item> <item name="green" type="color">#ff99cc00</item> <item name="orange" type="color">#ffffbb33</item> <item name="red" type="color">#ffff4444</item> <item name="darkblue" type="color">#ff0099cc</item> <item name="darkpurple" type="color">#ff9933cc</item> <item name="darkgreen" type="color">#ff669900</item> <item name="darkorange" type="color">#ffff8800</item> <item name="darkred" type="color">#ffcc0000</item> </resources>
there plenty of colors choose from.
update:
try change from
public myexitdialog(activity a) { super(a); this.c = a; }
to this
public myexitdialog(activity a) { super(a, r.style.customdialog); this.c = a; }
cleaner code:
use constructor.
public myexitdialog(activity a, int resid) { super(a, resid); this.c = a; }
and add resid inside parameter this.
myexitdialog mydialog = new myexitdialog(draweractivity.this, r.style.customdialog); mydialog.show();
update:
i'm sorry again giving wrong information. notice didn't use android:background
. change android:windowbackground
instead.
<resources> <style name="customdialog" parent="@style/theme.appcompat.light.dialog.alert"> <item name="android:windowisfloating">false</item> <item name="android:windowbackground">@color/red</item> </style> </resources>
hope helps.
Comments
Post a Comment