如何使用theme.xml和style.xml设置PopupMenu和AlertDialog的样式

时间:2013-04-21 16:59:33

标签: android alertdialog android-theme android-styles popupmenu

我想用多种颜色主题为我的Android应用程序设置外观。 这个指南/工具帮助我生成了基本的theme.xmlstyle.xml

但我无法弄清楚 PopupMenu AlertDialog 标题的样式?

我想仅使用我的应用主题更改颜色以简化颜色!

例:
before, taken from: developer.android.com/images/ui/dialogs.png

看起来像 after, taken from: developer.android.com/images/ui/dialog_custom.png

我正在使用Theme.Holo和Android SDK 21.1 RC3 / Tools 16.0。我已经尝试了很多风格和主题,但没有任何效果

1 个答案:

答案 0 :(得分: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);
    }
}

}

相关问题