安卓代码中找到当前主题颜色方法,还有其他方法希望能够赐教
第一种方法
TypedArray array = getTheme().obtainStyledAttributes(new int[] { android.R.attr.colorBackground, android.R.attr.textColorPrimary, }); int backgroundColor = array.getColor(0, 0xFF00FF); int textColor = array.getColor(1, 0xFF00FF); array.recycle();
第二种方法
/** * 获取主题颜色 * @return */ public int getColorPrimary(){ TypedValue typedValue = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); return typedValue.data; } /** * 获取主题颜色 * @return */ public int getDarkColorPrimary(){ TypedValue typedValue = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); return typedValue.data; }