Android 如何使用theme.xml和style.xml设置弹出菜单和AlertDialog的样式
我想为我的Android应用程序添加多种颜色主题。 这些指南/工具帮助我生成了基本的Android 如何使用theme.xml和style.xml设置弹出菜单和AlertDialog的样式,android,android-alertdialog,android-theme,android-styles,popupmenu,Android,Android Alertdialog,Android Theme,Android Styles,Popupmenu,我想为我的Android应用程序添加多种颜色主题。 这些指南/工具帮助我生成了基本的theme.xml和style.xml 但是我想不出如何设置弹出菜单和警报对话框标题的样式 我只想更改颜色,使其与我的应用程序主题一致 示例: 看起来像 我使用的是Theme.Holo和Android SDK 21.1 RC3/Tools 16.0。我尝试了很多风格和主题,但都没有成功 public class AlertDialogThemed extends AlertDialog { publ
theme.xml
和style.xml
看起来像
我使用的是
Theme.Holo
和Android SDK 21.1 RC3/Tools 16.0。我尝试了很多风格和主题,但都没有成功
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);
}
}
}