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