本文整理汇总了Java中android.support.v7.content.res.AppCompatResources.getColorStateList方法的典型用法代码示例。如果您正苦于以下问题:Java AppCompatResources.getColorStateList方法的具体用法?Java AppCompatResources.getColorStateList怎么用?Java AppCompatResources.getColorStateList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.content.res.AppCompatResources
的用法示例。
在下文中一共展示了AppCompatResources.getColorStateList方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getColorStateList
import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
public ColorStateList getColorStateList(int attr) {
int index = getAttributeIndex(attr);
int res = mArray.getResourceId(index, 0);
if (res != 0) {
ColorStateList v = AppCompatResources.getColorStateList(mContext, res);
if (v != null)
return v;
}
return mArray.getColorStateList(index);
}
示例2: getColorStateList
import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
@Nullable
public static ColorStateList getColorStateList(Context context, TypedArray original, int index) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return original.getColorStateList(index);
}
int resId = original.getResourceId(index, 0);
return AppCompatResources.getColorStateList(context, resId);
}
示例3: getColorStateList
import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
/**
* Returns the {@link ColorStateList} from the given attributes. The resource can include
* themeable attributes, regardless of API level.
*/
@Nullable
public static ColorStateList getColorStateList(
Context context, TypedArray attributes, @StyleableRes int index) {
if (attributes.hasValue(index)) {
int resourceId = attributes.getResourceId(index, 0);
if (resourceId != 0) {
ColorStateList value = AppCompatResources.getColorStateList(context, resourceId);
if (value != null) {
return value;
}
}
}
return attributes.getColorStateList(index);
}
示例4: onCreate
import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//noinspection ConstantConditions
getSupportActionBar().setSubtitle(
getString(R.string.api_version_format, Build.VERSION.SDK_INT));
// (1)
int deprecatedTextColor = getResources().getColor(R.color.button_text_csl);
initButtonTextColors(R.id.example1, deprecatedTextColor);
// (2)
ColorStateList deprecatedTextCsl = getResources().getColorStateList(R.color.button_text_csl);
initButtonTextColors(R.id.example2, deprecatedTextCsl);
// (3)
int textColorXml = AppCompatResources.getColorStateList(this, R.color.button_text_csl).getDefaultColor();
initButtonTextColors(R.id.example3, textColorXml);
// (4)
ColorStateList textCslXml = AppCompatResources.getColorStateList(this, R.color.button_text_csl);
initButtonTextColors(R.id.example4, textCslXml);
// (5)
ViewGroup container5 = (ViewGroup) findViewById(R.id.example5);
ColorStateList textCslXmlWithCustomTheme =
AppCompatResources.getColorStateList(container5.getContext(), R.color.button_text_csl);
initButtonTextColors(R.id.example5, textCslXmlWithCustomTheme);
// (6)
int textColorJava = getThemeAttrColor(this, R.attr.colorPrimary);
initButtonTextColors(R.id.example6, textColorJava);
// (7)
ColorStateList textCslJava = createColorStateList(this);
initButtonTextColors(R.id.example7, textCslJava);
// (8)
ViewGroup container8 = (ViewGroup) findViewById(R.id.example8);
ColorStateList textCslJavaWithCustomTheme = createColorStateList(container8.getContext());
initButtonTextColors(R.id.example8, textCslJavaWithCustomTheme);
}