最近工作中遇到一个问题,AlertDialog的显示因为风格由于Activity的Theme改变,而变化了。但是想把AlertDialog的显示风格还原成原来的样子。
问题:Activity使用的Theme影响了AlertDialog的显示风格,如何在保持Activity原有Theme的情况下,修改AlertDialog的风格呢?
答:一般AlertDialog的创建使用AlertDialog dialog = AlertDialog.Builder(Context context);AlertDialog dialog = AlertDialog.Builder(Context context, int int themeResId);如果使用themeResId,就可以指定Dialog的主题在AlertDialog.java文件中有如下定义public static final int THEME_TRADITIONAL = 1;public static final int THEME_HOLO_DARK = 2;public static final int THEME_HOLO_LIGHT = 3;public static final int THEME_DEVICE_DEFAULT_DARK = 4;public static final int THEME_DEVICE_DEFAULT_LIGHT = 5这些是AlertDialog的默认一些主题,在需要默认的一些Theme时,可以使用;当然也可以使用自定义的Theme。进一步研究可以查看源码
新闻热点
疑难解答