本文整理匯總了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);
}