本文整理汇总了Java中android.support.annotation.StyleableRes类的典型用法代码示例。如果您正苦于以下问题:Java StyleableRes类的具体用法?Java StyleableRes怎么用?Java StyleableRes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StyleableRes类属于android.support.annotation包,在下文中一共展示了StyleableRes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveThemeColors
import android.support.annotation.StyleableRes; //导入依赖的package包/类
@ColorInt
private static int[] resolveThemeColors(@NonNull Context context, @AttrRes @StyleableRes int[] attrs, @ColorInt int[] defaultColors) {
if (attrs.length != defaultColors.length)
throw new IllegalArgumentException("Argument attrs must be the same size as defaultColors");
TypedValue typedValue = new TypedValue();
TypedArray a = context.obtainStyledAttributes(typedValue.data, attrs);
for (int i = 0; i < attrs.length; i++) {
defaultColors[i] = a.getColor(0, defaultColors[i]);
}
a.recycle();
return defaultColors;
}
示例2: initCustomFont
import android.support.annotation.StyleableRes; //导入依赖的package包/类
public static void initCustomFont(TextView view, AttributeSet attributeSet,
@StyleableRes int[] attrs, int attrIndex) {
TypedArray typedArray = view.getContext().getTheme()
.obtainStyledAttributes(attributeSet, attrs, 0, 0);
try {
int fontIndex = typedArray.getInt(attrIndex, DEFAULT_FONT);
String fontPath = FONTS.get(fontIndex);
if (fontPath != null) {
view.setTypeface(Typeface.createFromAsset(view.getContext().getAssets(), fontPath));
} else {
throw new IllegalArgumentException("invalid font path");
}
} finally {
typedArray.recycle();
}
}
示例3: resolveThemeColors
import android.support.annotation.StyleableRes; //导入依赖的package包/类
@ColorInt
private static int[] resolveThemeColors(@NonNull Context context, @AttrRes @StyleableRes int[] attrs, @ColorInt int[] defaultColors) {
if (attrs.length != defaultColors.length)
throw new IllegalArgumentException("Argument attrs must be the same size as defaultColors");
TypedValue typedValue = new TypedValue();
//noinspection ResourceType
TypedArray a = context.obtainStyledAttributes(typedValue.data, attrs);
for (int i = 0; i < attrs.length; i++) {
defaultColors[i] = a.getColor(0, defaultColors[i]);
}
a.recycle();
return defaultColors;
}
示例4: initPrevState
import android.support.annotation.StyleableRes; //导入依赖的package包/类
private ToolbarState initPrevState(Toolbar toolbar) {
ToolbarState prevState = new ToolbarState();
if (toolbar.getBackground() != null) {
prevState.toolbarColor = ((ColorDrawable) (toolbar.getBackground())).getColor();
}
Context context = toolbar.getContext();
TypedValue typedValue = new TypedValue();
TypedArray attr = context.obtainStyledAttributes(typedValue.data,
new int[]{R.attr.colorPrimary, R.attr.colorPrimaryDark});
if (attr != null) {
if (prevState.toolbarColor > 0) {
prevState.toolbarColor = attr.getColor(0, 0);
}
@StyleableRes int index = 1;
prevState.statusBarColor = attr.getColor(index, prevState.toolbarColor);
attr.recycle();
}
if (toolbar.getTitle() != null) {
prevState.title = toolbar.getTitle().toString();
}
if (toolbar.getSubtitle() != null) {
prevState.subTitle = toolbar.getSubtitle().toString();
}
prevState.title = prevState.title != null ? prevState.title : EMPTY;
prevState.subTitle = prevState.subTitle != null ? prevState.subTitle : EMPTY;
prevState.logo = toolbar.getLogo();
prevState.navigationIcon = toolbar.getNavigationIcon();
return prevState;
}
示例5: onGlobalLayoutChange
import android.support.annotation.StyleableRes; //导入依赖的package包/类
public void onGlobalLayoutChange(@StyleableRes int headerRes, @StyleableRes int footerRes){
int headerId = mTypedArrayResourceProvider.getResourceId(headerRes);
if(headerId != 0) {
mStickyScrollPresentation.initHeaderView(headerId);
}
int footerId = mTypedArrayResourceProvider.getResourceId(footerRes);
if(footerId != 0){
mStickyScrollPresentation.initFooterView(footerId);
}
mTypedArrayResourceProvider.recycle();
}
示例6: getDrawable
import android.support.annotation.StyleableRes; //导入依赖的package包/类
public static Drawable getDrawable(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex) {
Drawable val = a.getDrawable(index);
if (val == null) {
return a.getDrawable(fallbackIndex);
}
return val;
}
示例7: getString
import android.support.annotation.StyleableRes; //导入依赖的package包/类
public static String getString(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex) {
String val = a.getString(index);
if (val == null) {
return a.getString(fallbackIndex);
}
return val;
}
示例8: getTextArray
import android.support.annotation.StyleableRes; //导入依赖的package包/类
public static CharSequence[] getTextArray(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex) {
CharSequence[] val = a.getTextArray(index);
if (val == null) {
return a.getTextArray(fallbackIndex);
}
return val;
}
示例9: resolveColorAttributesFromTheme
import android.support.annotation.StyleableRes; //导入依赖的package包/类
@NonNull
private static int[] resolveColorAttributesFromTheme(Context context, @StyleableRes int[] attrs) {
final TypedArray ta = context.obtainStyledAttributes(attrs);
final int[] colors = new int[attrs.length];
for (int idxAttr = 0; idxAttr < colors.length; idxAttr++) {
colors[idxAttr] = ta.getColor(idxAttr, 0);
}
ta.recycle();
return colors;
}
示例10: getDimension
import android.support.annotation.StyleableRes; //导入依赖的package包/类
@Px
static int getDimension(Context context,
TypedArray array,
@StyleableRes int attr,
@DimenRes int defaultDimenRes) {
return array.getDimensionPixelOffset(
attr, context.getResources().getDimensionPixelSize(defaultDimenRes));
}
示例11: getColor
import android.support.annotation.StyleableRes; //导入依赖的package包/类
@ColorInt
static int getColor(Context context,
TypedArray array,
@StyleableRes int attr,
@ColorRes int defaultColorRes) {
if (Build.VERSION.SDK_INT >= 23) {
return array.getColor(attr, context.getColor(defaultColorRes));
} else {
return array.getColor(attr, context.getResources().getColor(defaultColorRes));
}
}
示例12: getColors
import android.support.annotation.StyleableRes; //导入依赖的package包/类
@ColorInt
static int[] getColors(Context context,
TypedArray array,
@StyleableRes int attr,
@ArrayRes int defaultColorsRes) {
return context.getResources().getIntArray(
array.getResourceId(attr, defaultColorsRes));
}
示例13: getInteger
import android.support.annotation.StyleableRes; //导入依赖的package包/类
static int getInteger(Context context,
TypedArray array,
@StyleableRes int attr,
@IntegerRes int defaultIntRes) {
return array.getInteger(
attr, context.getResources().getInteger(defaultIntRes));
}
示例14: FixedSizeLayout
import android.support.annotation.StyleableRes; //导入依赖的package包/类
@SuppressWarnings("ResourceType")
public FixedSizeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
@StyleableRes int[] sizeAttrs = { android.R.attr.maxWidth, android.R.attr.maxHeight };
TypedArray a = context.obtainStyledAttributes(attrs, sizeAttrs);
mMaxLayoutWidth = a.getLayoutDimension(0, -1);
mMaxLayoutHeight = a.getLayoutDimension(1, -1);
a.recycle();
}
示例15: loadColor
import android.support.annotation.StyleableRes; //导入依赖的package包/类
/**
* Load the color from xml attributes or fallback to the default if not found
*
* @param typedArray attributes typed array
* @param index the styleable index
* @param defaultColor the default color resource id
* @return the color to use
*/
@ColorInt
private int loadColor(TypedArray typedArray, @StyleableRes int index, @ColorRes int defaultColor) {
int loadedColor = ContextCompat.getColor(getContext(), defaultColor);
ColorStateList colorList = typedArray.getColorStateList(index);
if (colorList != null) {
loadedColor = colorList.getDefaultColor();
}
return loadedColor;
}