【发布时间】:2017-09-07 05:32:57
【问题描述】:
我有一些样式主题,可以选择。和setTheme(getThemeResId()) 在BaseActivity。在我需要的任何地方,我都会通过?attr/colorPrimary 获得主色。但在设置中,我想显示所有主题颜色。喜欢getColor(R.attr.colorPrimary, R.style.AppTheme1)。如何做到这一点?
【问题讨论】:
标签: android
我有一些样式主题,可以选择。和setTheme(getThemeResId()) 在BaseActivity。在我需要的任何地方,我都会通过?attr/colorPrimary 获得主色。但在设置中,我想显示所有主题颜色。喜欢getColor(R.attr.colorPrimary, R.style.AppTheme1)。如何做到这一点?
【问题讨论】:
标签: android
int[] attrs = { R.attr.colorPrimary, R.attr.colorAccent, R.attr.colorSecondary };
TypedArray ta = getContext().obtainStyledAttributes(R.style.AppTheme1, attrs);
int colorPrimary = ta.getColor(0, Color.BLACK);
int colorAccent = ta.getColor(1, Color.BLACK);
int colorSecondary = ta.getColor(2, Color.BLACK);
Log.i("LOG", "colorPrimary as hex:" + Integer.toHexString(colorPrimary));
【讨论】: