Android的:如何获得活动的背景颜色在Java中?如何获得、颜色、背景、Android

2023-09-12 04:28:09 作者:魍魉影魅

我怎样才能得到背景颜色和文字颜色(默认为子视图)的活动中的Java?

解决方案

  TypedArray阵列= getTheme()。obtainStyledAttributes(新INT [] {
    android.R.attr.colorBackground,
    android.R.attr.textColorPrimary,
});
INT的backgroundColor = array.getColor(0,0xFF00FF);
INT文字颜色= array.getColor(1,0xFF00FF);
array.recycle();
 

How can I get background color and text color (default for child views) of an Activity in Java?

解决方案 一周机情烩 荣耀新旗舰对标华为P Mate系 1999元 捣乱 新机发布

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();