【问题标题】:How to style PopupMenu and AlertDialog with theme.xml and style.xml如何使用 theme.xml 和 style.xml 设置 PopupMenu 和 AlertDialog 的样式
【发布时间】:2013-04-21 16:59:32
【问题描述】:
我想为我的 Android 应用添加多个颜色主题。
本指南/工具帮助我生成了基本的 theme.xml 和 style.xml
但我无法确定 PopupMenu 和 AlertDialog 标题的样式?
我只想更改颜色以简化我的应用主题!
示例:
看起来像
我正在使用Theme.Holo 和 Android SDK 21.1 RC3/Tools 16.0。我已经尝试了很多样式和主题,但没有任何效果
【问题讨论】:
标签:
android
android-alertdialog
android-theme
android-styles
popupmenu
【解决方案1】:
public class AlertDialogThemed extends AlertDialog {
public AlertDialogThemed(Context context) {
super(context);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Resources resources = getContext().getResources();
final int color = resources.getColor(R.color.dialog_color);
final View title = findViewById(resources.getIdentifier("alertTitle", "id", "android"));
if (title != null) {
((TextView) title).setTextColor(color);
}
final View titleDivider = findViewById(resources.getIdentifier("titleDivider", "id", "android"));
if (titleDivider != null) {
titleDivider.setBackgroundColor(color);
}
}
}