本文整理了Java中android.content.Context.getTheme()
方法的一些代码示例,展示了Context.getTheme()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.getTheme()
方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:getTheme
暂无
代码示例来源:origin: chrisbanes/cheesesquare
public SimpleStringRecyclerViewAdapter(Context context, List<String> items) {
context.getTheme().resolveAttribute(R.attr.selectableItemBackground, mTypedValue, true);
mBackground = mTypedValue.resourceId;
mValues = items;
}
代码示例来源:origin: Bearded-Hen/Android-Bootstrap
@SuppressWarnings("deprecation")
public static Drawable resolveDrawable(@DrawableRes int resId, Context context) {
Resources resources = context.getResources();
Resources.Theme theme = context.getTheme();
if (Build.VERSION.SDK_INT >= 22) {
return resources.getDrawable(resId, theme);
}
else {
return resources.getDrawable(resId);
}
}
代码示例来源:origin: aa112901/remusic
public void setIconColor(Drawable icon) {
int textColorSecondary = android.R.attr.textColorSecondary;
TypedValue value = new TypedValue();
if (!mContext.getTheme().resolveAttribute(textColorSecondary, value, true)) {
return;
}
int baseColor = mContext.getResources().getColor(value.resourceId);
icon.setColorFilter(baseColor, PorterDuff.Mode.MULTIPLY);
}
}
代码示例来源:origin: nickbutcher/plaid
public static int getActionBarSize(@NonNull Context context) {
TypedValue value = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.actionBarSize, value, true);
int actionBarSize = TypedValue.complexToDimensionPixelSize(
value.data, context.getResources().getDisplayMetrics());
return actionBarSize;
}
代码示例来源:origin: mikepenz/MaterialDrawer
/**
* Get the boolean value of a given styleable.
*
* @param ctx
* @param styleable
* @param def
* @return
*/
public static boolean getBooleanStyleable(Context ctx, @StyleableRes int styleable, boolean def) {
TypedArray ta = ctx.getTheme().obtainStyledAttributes(R.styleable.MaterialDrawer);
return ta.getBoolean(styleable, def);
}
代码示例来源:origin: roughike/BottomBar
@NonNull protected static TypedValue getTypedValue(@NonNull Context context, @AttrRes int resId) {
TypedValue tv = new TypedValue();
context.getTheme().resolveAttribute(resId, tv, true);
return tv;
}
代码示例来源:origin: zhihu/Matisse
public AlbumMediaAdapter(Context context, SelectedItemCollection selectedCollection, RecyclerView recyclerView) {
super(null);
mSelectionSpec = SelectionSpec.getInstance();
mSelectedCollection = selectedCollection;
TypedArray ta = context.getTheme().obtainStyledAttributes(new int[]{R.attr.item_placeholder});
mPlaceholder = ta.getDrawable(0);
ta.recycle();
mRecyclerView = recyclerView;
}
代码示例来源:origin: google/ExoPlayer
public AspectRatioFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
resizeMode = RESIZE_MODE_FIT;
if (attrs != null) {
TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
R.styleable.AspectRatioFrameLayout, 0, 0);
try {
resizeMode = a.getInt(R.styleable.AspectRatioFrameLayout_resize_mode, RESIZE_MODE_FIT);
} finally {
a.recycle();
}
}
aspectRatioUpdateDispatcher = new AspectRatioUpdateDispatcher();
}
代码示例来源:origin: naman14/Timber
public static int getActionBarHeight(Context context) {
int mActionBarHeight;
TypedValue mTypedValue = new TypedValue();
context.getTheme().resolveAttribute(R.attr.actionBarSize, mTypedValue, true);
mActionBarHeight = TypedValue.complexToDimensionPixelSize(mTypedValue.data, context.getResources().getDisplayMetrics());
return mActionBarHeight;
}
代码示例来源:origin: TeamNewPipe/NewPipe
/**
* Get a color from an attr styled according to the the context's theme.
*/
public static int resolveColorFromAttr(Context context, @AttrRes int attrColor) {
final TypedValue value = new TypedValue();
context.getTheme().resolveAttribute(attrColor, value, true);
if (value.resourceId != 0) {
return ContextCompat.getColor(context, value.resourceId);
}
return value.data;
}
代码示例来源:origin: scwang90/SmartRefreshLayout
@SuppressWarnings("deprecation")
public void setColorSchemeColorIds(@IdRes int... resources) {
final View thisView = this;
final Resources res = thisView.getResources();
final int[] colorRes = new int[resources.length];
for (int i = 0; i < resources.length; i++) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
colorRes[i] = res.getColor(resources[i], getContext().getTheme());
} else {
colorRes[i] = res.getColor(resources[i]);
}
}
mProgress.setColorSchemeColors(colorRes);
}
//</editor-fold>
代码示例来源:origin: bumptech/glide
private static Drawable getDrawable(
Context ourContext, Context targetContext, @DrawableRes int id, @Nullable Theme theme) {
try {
// Race conditions may cause us to attempt to load using v7 more than once. That's ok since
// this check is a modest optimization and the output will be correct anyway.
if (shouldCallAppCompatResources) {
return loadDrawableV7(targetContext, id, theme);
}
} catch (NoClassDefFoundError error) {
shouldCallAppCompatResources = false;
} catch (IllegalStateException e) {
if (ourContext.getPackageName().equals(targetContext.getPackageName())) {
throw e;
}
return ContextCompat.getDrawable(targetContext, id);
} catch (Resources.NotFoundException e) {
// Ignored, this can be thrown when drawable compat attempts to decode a canary resource. If
// that decode attempt fails, we still want to try with the v4 ResourcesCompat below.
}
return loadDrawableV4(targetContext, id, theme != null ? theme : targetContext.getTheme());
}
代码示例来源:origin: bumptech/glide
private Drawable loadDrawable(@DrawableRes int resourceId) {
Theme theme = requestOptions.getTheme() != null
? requestOptions.getTheme() : context.getTheme();
return DrawableDecoderCompat.getDrawable(glideContext, resourceId, theme);
}
代码示例来源:origin: aa112901/remusic
static int getAttrDimensionPixelOffset(Context context, AttributeSet attrs, int attr, int defaultValue) {
TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr});
final int value = a.getDimensionPixelOffset(0, defaultValue);
a.recycle();
return value;
}
代码示例来源:origin: aa112901/remusic
static int getAttrColor(Context context, AttributeSet attrs, int attr, int defaultValue) {
TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr});
final int colorId = a.getResourceId(0, 0);
final int value = colorId != 0 ? ThemeUtils.replaceColorById(context, colorId) : ThemeUtils.replaceColor(context, a.getColor(0, defaultValue));
a.recycle();
return value;
}
代码示例来源:origin: facebook/litho
public void init(ComponentContext context) {
mResources = context.getAndroidContext().getResources();
mTheme = context.getAndroidContext().getTheme();
mResourceCache = context.getResourceCache();
}
代码示例来源:origin: zhihu/Matisse
private void init() {
mSelectedColor = ResourcesCompat.getColor(
getResources(), R.color.zhihu_item_checkCircle_backgroundColor,
getContext().getTheme());
mUnSelectUdColor = ResourcesCompat.getColor(
getResources(), R.color.zhihu_check_original_radio_disable,
getContext().getTheme());
setChecked(false);
}
代码示例来源:origin: bumptech/glide
public void sameAs(@DrawableRes int resourceId) {
Context context = InstrumentationRegistry.getTargetContext();
Drawable drawable =
ResourcesCompat.getDrawable(context.getResources(), resourceId, context.getTheme());
sameAs(drawable);
}
代码示例来源:origin: JakeWharton/butterknife
@UiThread // Implicit synchronization for use of shared resource VALUE.
public static Drawable getTintedDrawable(Context context,
@DrawableRes int id, @AttrRes int tintAttrId) {
boolean attributeFound = context.getTheme().resolveAttribute(tintAttrId, VALUE, true);
if (!attributeFound) {
throw new Resources.NotFoundException("Required tint color attribute with name "
+ context.getResources().getResourceEntryName(tintAttrId)
+ " and attribute ID "
+ tintAttrId
+ " was not found.");
}
Drawable drawable = ContextCompat.getDrawable(context, id);
drawable = DrawableCompat.wrap(drawable.mutate());
int color = ContextCompat.getColor(context, VALUE.resourceId);
DrawableCompat.setTint(drawable, color);
return drawable;
}
代码示例来源:origin: googlesamples/easypermissions
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
getContext().getTheme().applyStyle(R.style.Theme_AppCompat, true);
return super.onCreateView(inflater, container, savedInstanceState);
}
内容来源于网络,如有侵权,请联系作者删除!