本文整理汇总了Java中android.content.res.Resources.Theme.obtainStyledAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java Theme.obtainStyledAttributes方法的具体用法?Java Theme.obtainStyledAttributes怎么用?Java Theme.obtainStyledAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.res.Resources.Theme
的用法示例。
在下文中一共展示了Theme.obtainStyledAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveAccentColor
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
@TargetApi(LOLLIPOP)
static int resolveAccentColor(Context context) {
Theme theme = context.getTheme();
// on Lollipop, grab system colorAccent attribute
// pre-Lollipop, grab AppCompat colorAccent attribute
// finally, check for custom mp_colorAccent attribute
int attr = isAtLeastL() ? android.R.attr.colorAccent : R.attr.colorAccent;
TypedArray typedArray = theme.obtainStyledAttributes(new int[] { attr, R.attr.mp_colorAccent });
int accentColor = typedArray.getColor(0, FALLBACK_COLOR);
accentColor = typedArray.getColor(1, accentColor);
typedArray.recycle();
return accentColor;
}
示例2: resolveAccentColor
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
@TargetApi(LOLLIPOP)
static int resolveAccentColor(Context context) {
Theme theme = context.getTheme();
// on Lollipop, grab system colorAccent attribute
// pre-Lollipop, grab AppCompat colorAccent attribute
// finally, check for custom mp_colorAccent attribute
int attr = isAtLeastL() ? android.R.attr.colorAccent : R.attr.colorAccent;
TypedArray typedArray = theme.obtainStyledAttributes(new int[]{attr, R.attr.mp_colorAccent});
int accentColor = typedArray.getColor(0, FALLBACK_COLOR);
accentColor = typedArray.getColor(1, accentColor);
typedArray.recycle();
return accentColor;
}
示例3: setup
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
private void setup(Context context, AttributeSet attrs) {
DisplayMetrics dm = getResources().getDisplayMetrics();
mPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, dm);
mStrokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, dm);
mRectF = new RectF();
mRect = new Rect();
mPaint = new Paint();
mPaint.setARGB(0x99, 0x33, 0x33, 0x33);
mPaint.setAntiAlias(true);
mPaint.setStrokeCap(Paint.Cap.BUTT);
if (attrs != null) {
Theme t = context.getTheme();
TypedArray a = t.obtainStyledAttributes(attrs, R.styleable.ProgressCircle, 0, 0);
try {
setMax(a.getInteger(R.styleable.ProgressCircle_max, 100));
setHollow(a.getBoolean(R.styleable.ProgressCircle_hollow, false));
} finally {
a.recycle();
}
}
}
示例4: applyPreloaderTheme
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
public void applyPreloaderTheme(Theme t) {
TypedArray ta = t.obtainStyledAttributes(R.styleable.PreloadIconDrawable);
mBgDrawable = ta.getDrawable(R.styleable.PreloadIconDrawable_background);
mBgDrawable.setFilterBitmap(true);
mPaint.setStrokeWidth(ta.getDimension(R.styleable.PreloadIconDrawable_indicatorSize, 0));
mRingOutset = ta.getDimensionPixelSize(R.styleable.PreloadIconDrawable_ringOutset, 0);
ta.recycle();
onBoundsChange(getBounds());
invalidateSelf();
}
示例5: getThemeAttributeColor
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
public static int getThemeAttributeColor(Context context, int attr) {
TypedArray a = null;
try {
Theme theme = context.getTheme();
int[] iArr = new int[COLOR_DEFAULT];
iArr[0] = attr;
a = theme.obtainStyledAttributes(iArr);
int color = a.getColor(0, 0);
return color;
} finally {
if (a != null) {
a.recycle();
}
}
}
示例6: setValue
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void setValue(Theme newTheme, int themeId) {
if (mView == null) {
return;
}
TypedArray a = newTheme.obtainStyledAttributes(themeId,
new int[]{mAttrResId});
int attributeResourceId = a.getResourceId(0, 0);
Drawable drawable = mView.getResources().getDrawable(
attributeResourceId);
a.recycle();
mView.setBackgroundDrawable(drawable);
}
示例7: setValue
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void setValue(Theme newTheme, int themeId) {
if ( mView == null ) {
return ;
}
TypedArray a = newTheme.obtainStyledAttributes(themeId,
new int[] { mAttrResId });
int attributeResourceId = a.getResourceId(0, 0);
Drawable drawable = mView.getResources().getDrawable(
attributeResourceId);
a.recycle();
mView.setBackgroundDrawable(drawable);
}
示例8: getToolbarHeight
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
/**
* Retrieves the toolbar height of the current app theme.
*
* @param theme the device {@link Theme}
* @param actionBarSize the current {@link ActionBar} size
* @return the toolbar height of the current app theme
*/
@Dimension(unit = Dimension.DP)
public static int getToolbarHeight(@NonNull Theme theme, @AttrRes int actionBarSize) {
final TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] {actionBarSize});
int toolbarHeight = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();
return toolbarHeight;
}
示例9: getThemeColor
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
public static int getThemeColor(Context context, int id) {
Theme theme = context.getTheme();
TypedArray a = theme.obtainStyledAttributes(new int[]{id});
int result = a.getColor(0, DEFAULT_COLOR);
a.recycle();
return result;
}
示例10: getThemeDark
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
public static boolean getThemeDark(Context context, int id) {
Theme theme = context.getTheme();
TypedArray a = theme.obtainStyledAttributes(new int[]{id});
boolean result = a.getBoolean(0, false);
a.recycle();
return result;
}
示例11: getThemeDrawable
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
public static Drawable getThemeDrawable(Context context, int res) {
Theme theme = context.getTheme();
TypedArray a = theme.obtainStyledAttributes(new int[]{res});
Drawable result = a.getDrawable(0);
a.recycle();
return result;
}
示例12: resolveAccentColor
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
@SuppressWarnings("ResourceType")
@TargetApi(LOLLIPOP)
public static int resolveAccentColor(Context context) {
Theme theme = context.getTheme();
int attr = isAtLeastL() ? android.R.attr.colorAccent : R.attr.colorAccent;
TypedArray typedArray = theme.obtainStyledAttributes(new int[] { attr, R.attr.mp_colorAccent });
int accentColor = typedArray.getColor(0, FALLBACK_COLOR);
accentColor = typedArray.getColor(1, accentColor);
typedArray.recycle();
return accentColor;
}
示例13: getColor
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
/**
* Returns color for attr from the {@link Theme}
*
* @param theme {@link Theme} to get int from
* @param attr Attribute of the int
* @return dimension for attr from the {@link Theme}
*/
@ColorInt
public static int getColor(@NonNull final Theme theme, @AttrRes final int attr) {
final TypedArray array = theme.obtainStyledAttributes(new int[]{attr});
try {
return array.getColor(0, Color.TRANSPARENT);
} finally {
array.recycle();
}
}
示例14: getColorStateList
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
/**
* Returns {@link ColorStateList} for attr from the {@link Theme}
*
* @param theme {@link Theme} to get int from
* @param attr Attribute of the int
* @return dimension for attr from the {@link Theme}
*/
@Nullable
public static ColorStateList getColorStateList(@NonNull final Theme theme,
@AttrRes final int attr) {
final TypedArray array = theme.obtainStyledAttributes(new int[]{attr});
try {
return array.getColorStateList(0);
} finally {
array.recycle();
}
}
示例15: obtainAttributes
import android.content.res.Resources.Theme; //导入方法依赖的package包/类
static TypedArray obtainAttributes(Resources res, Theme theme, AttributeSet set, int[] attrs) {
if (theme == null) {
return res.obtainAttributes(set, attrs);
}
return theme.obtainStyledAttributes(set, attrs, 0, 0);
}