本文整理汇总了Java中android.content.Context.getTheme方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getTheme方法的具体用法?Java Context.getTheme怎么用?Java Context.getTheme使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Context
的用法示例。
在下文中一共展示了Context.getTheme方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processAttributes
import android.content.Context; //导入方法依赖的package包/类
/**
* Load given attributes to inner variables,
*
* @param context
* @param attrs
*/
private void processAttributes(Context context, AttributeSet attrs) {
Theme theme = context.getTheme();
TypedValue outValue = new TypedValue();
boolean found = theme.resolveAttribute(R.attr.iconActionCollapse, outValue, true);
if (found) {
mIconActionCollapseId = outValue.resourceId;
}
found = theme.resolveAttribute(R.attr.iconActionExpand, outValue, true);
if (found) {
mIconActionExpandId = outValue.resourceId;
}
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.FoldableLinearLayout, 0, 0);
mFoldedLabel = a.getString(R.styleable.FoldableLinearLayout_foldedLabel);
mUnFoldedLabel = a.getString(R.styleable.FoldableLinearLayout_unFoldedLabel);
a.recycle();
}
// If any attribute isn't found then set a default one
mFoldedLabel = (mFoldedLabel == null) ? "No text!" : mFoldedLabel;
mUnFoldedLabel = (mUnFoldedLabel == null) ? "No text!" : mUnFoldedLabel;
}
示例2: pullFontPathFromTheme
import android.content.Context; //导入方法依赖的package包/类
/**
* Last but not least, try to pull the Font Path from the Theme, which is defined.
*
* @param context Activity Context
* @param styleAttrId Theme style id
* @param attributeId if -1 returns null.
* @return null if no theme or attribute defined.
*/
static String pullFontPathFromTheme(Context context, int styleAttrId, int[] attributeId) {
if (styleAttrId == -1 || attributeId == null)
return null;
final Resources.Theme theme = context.getTheme();
final TypedValue value = new TypedValue();
theme.resolveAttribute(styleAttrId, value, true);
final TypedArray typedArray = theme.obtainStyledAttributes(value.resourceId, attributeId);
try {
String font = typedArray.getString(0);
return font;
} catch (Exception ignore) {
// Failed for some reason.
return null;
} finally {
typedArray.recycle();
}
}
示例3: resolveAccentColor
import android.content.Context; //导入方法依赖的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;
}
示例4: getThemeColor
import android.content.Context; //导入方法依赖的package包/类
/** [这个好像好用些] */
public static int getThemeColor(Context context, int themeRes, int attribute, int defaultColor) {
int themeColor = 0;
String packageName = context.getPackageName();
try {
Context packageContext = context.createPackageContext(packageName, 0);
packageContext.setTheme(themeRes);
Resources.Theme theme = packageContext.getTheme();
TypedArray ta = theme.obtainStyledAttributes(new int[] {attribute});
themeColor = ta.getColor(0, defaultColor);
ta.recycle();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return themeColor;
}
示例5: processAttributes
import android.content.Context; //导入方法依赖的package包/类
/**
*/
@Override
void processAttributes(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super.processAttributes(context, attrs, defStyleAttr, defStyleRes);
if (!mWidget.isInEditMode()) {
final Resources.Theme theme = context.getTheme();
// Try to apply font presented within text appearance style.
final TypedArray appearanceAttributes = theme.obtainStyledAttributes(attrs, new int[]{android.R.attr.textAppearance}, defStyleAttr, defStyleRes);
final int appearance = appearanceAttributes.getResourceId(0, -1);
if (appearance != -1) {
FontApplier.DEFAULT.applyFont(mWidget, appearance);
}
appearanceAttributes.recycle();
// Try to apply font presented within xml attributes.
FontApplier.DEFAULT.applyFont(mWidget, attrs, defStyleAttr, defStyleRes);
}
}
示例6: configureMenuItem
import android.content.Context; //导入方法依赖的package包/类
/**
* Performs configuration for a {@link MenuItem} determined by the given <var>configuration</var>.
*
* @param configuration The configuration object carrying all necessary data to perform menu item
* configuration.
* @param context Context used to resolve current theme attributes.
* @return {@code True} if configuration has been performed, {@code false} if not due to invalid
* menu item id or menu specified for the given <var>configuration</var> object.
*/
public static boolean configureMenuItem(@NonNull ItemConfiguration configuration, @NonNull Context context) {
if (configuration.itemId == ItemConfiguration.NO_ID) {
return false;
}
final MenuItem menuItem = configuration.menu.findItem(configuration.itemId);
if (menuItem == null) {
return false;
}
final Resources resources = context.getResources();
final Resources.Theme theme = context.getTheme();
Drawable icon = null;
if (configuration.icon != null) {
icon = configuration.icon;
} else if (configuration.vectorIconResId != ItemConfiguration.NO_ID) {
icon = ResourceUtils.getVectorDrawable(resources, configuration.vectorIconResId, theme);
} else if (configuration.iconResId != ItemConfiguration.NO_ID) {
icon = ResourceUtils.getDrawable(resources, configuration.iconResId, theme);
}
if (icon != null) {
icon = applyIconTint(icon, configuration);
menuItem.setIcon(icon);
}
return true;
}
示例7: calculateActionBarSize
import android.content.Context; //导入方法依赖的package包/类
/** Calculates the Action Bar height in pixels. */
public static int calculateActionBarSize(Context context) {
if (context == null) {
return 0;
}
Resources.Theme curTheme = context.getTheme();
if (curTheme == null) {
return 0;
}
TypedArray att = curTheme.obtainStyledAttributes(RES_IDS_ACTION_BAR_SIZE);
if (att == null) {
return 0;
}
float size = att.getDimension(0, 0);
att.recycle();
return (int) size;
}
示例8: getDrawable
import android.content.Context; //导入方法依赖的package包/类
/**
* Get drawable
*
* @param context context
* @param resId drawable id
* @return drawable
*/
static public Drawable getDrawable(@NonNull final Context context, int resId)
{
final Resources resources = context.getResources();
Drawable drawable;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP)
{
final Resources.Theme theme = context.getTheme();
drawable = resources.getDrawable(resId, theme);
}
else
{
drawable = resources.getDrawable(resId);
}
return drawable;
}
示例9: init
import android.content.Context; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void init(Context context) {
// Set min width
Resources.Theme theme = context.getTheme();
int resId = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT
? android.R.attr.windowMinWidthMinor
: android.R.attr.windowMinWidthMajor;
TypedValue tv = new TypedValue();
theme.resolveAttribute(resId, tv, true);
if (tv.type == TypedValue.TYPE_DIMENSION) {
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
setMinWidthSize((int) tv.getDimension(metrics));
} else if (tv.type == TypedValue.TYPE_FRACTION) {
setMiniWidthPercent(tv.getFraction(1, 1));
}
// Set background
Drawable drawable = AttrResources.getAttrDrawable(context, android.R.attr.windowBackground);
setBackgroundDrawable(drawable);
// Set elevation
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
float elevation = AttrResources.getAttrDimension(context, android.R.attr.windowElevation);
setElevation(elevation);
}
}
示例10: init
import android.content.Context; //导入方法依赖的package包/类
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
final Resources.Theme theme = context.getTheme();
int[] styles = new int[]{-2000244};
TypedArray a = theme.obtainStyledAttributes(
attrs, styles, defStyleAttr, 0);
int n = a.getIndexCount();
for (int i = 0; i < n; i++) {
int attr = a.getIndex(i);
switch (attr) {
case -2002018:
mText = a.getText(attr);
break;
}
}
a.recycle();
if (!TextUtils.isEmpty(mText)) {
setColorText((String) mText);
}
}
示例11: getColorAttr
import android.content.Context; //导入方法依赖的package包/类
@ColorInt private static int getColorAttr(@NonNull Context context, int attr) {
Resources.Theme theme = context.getTheme();
TypedArray typedArray = theme.obtainStyledAttributes(new int[]{attr});
final int color = typedArray.getColor(0, Color.LTGRAY);
typedArray.recycle();
return color;
}
示例12: initializePanelMenu
import android.content.Context; //导入方法依赖的package包/类
private boolean initializePanelMenu(PanelFeatureState st) {
Context context = this.mContext;
if ((st.featureId == 0 || st.featureId == 108) && this.mDecorContentParent != null) {
TypedValue outValue = new TypedValue();
Theme baseTheme = context.getTheme();
baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true);
Theme widgetTheme = null;
if (outValue.resourceId != 0) {
widgetTheme = context.getResources().newTheme();
widgetTheme.setTo(baseTheme);
widgetTheme.applyStyle(outValue.resourceId, true);
widgetTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
} else {
baseTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
}
if (outValue.resourceId != 0) {
if (widgetTheme == null) {
widgetTheme = context.getResources().newTheme();
widgetTheme.setTo(baseTheme);
}
widgetTheme.applyStyle(outValue.resourceId, true);
}
if (widgetTheme != null) {
Context context2 = new ContextThemeWrapper(context, 0);
context2.getTheme().setTo(widgetTheme);
context = context2;
}
}
MenuBuilder menu = new MenuBuilder(context);
menu.setCallback(this);
st.setMenu(menu);
return true;
}
示例13: getDefaultColors
import android.content.Context; //导入方法依赖的package包/类
private static int[] getDefaultColors(Context context) {
Resources.Theme theme = context.getTheme();
TypedArray toolbarStyle = null;
TypedArray textAppearances = null;
TypedArray titleTextAppearance = null;
TypedArray subtitleTextAppearance = null;
try {
toolbarStyle = theme
.obtainStyledAttributes(new int[]{R.attr.toolbarStyle});
int toolbarStyleResId = toolbarStyle.getResourceId(0, 0);
textAppearances = theme.obtainStyledAttributes(
toolbarStyleResId, new int[]{
R.attr.titleTextAppearance,
R.attr.subtitleTextAppearance,
});
int titleTextAppearanceResId = textAppearances.getResourceId(0, 0);
int subtitleTextAppearanceResId = textAppearances.getResourceId(1, 0);
titleTextAppearance = theme
.obtainStyledAttributes(titleTextAppearanceResId, new int[]{android.R.attr.textColor});
subtitleTextAppearance = theme
.obtainStyledAttributes(subtitleTextAppearanceResId, new int[]{android.R.attr.textColor});
int titleTextColor = titleTextAppearance.getColor(0, Color.BLACK);
int subtitleTextColor = subtitleTextAppearance.getColor(0, Color.BLACK);
return new int[] {titleTextColor, subtitleTextColor};
} finally {
recycleQuietly(toolbarStyle);
recycleQuietly(textAppearances);
recycleQuietly(titleTextAppearance);
recycleQuietly(subtitleTextAppearance);
}
}
示例14: init
import android.content.Context; //导入方法依赖的package包/类
private void init(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int
defStyleRes) {
mAttrsHelper.init(context, attrs, defStyleAttr, defStyleRes);
setText(mAttrsHelper.mText);
TextPaint textPaint = getTextPaint();
textPaint.setColor(mAttrsHelper.mTextColor);
textPaint.setTextSize(mAttrsHelper.mTextSize);
final Resources.Theme theme = context.getTheme();
TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.FastTextView, defStyleAttr,
defStyleRes);
mEnableLayoutCache = a.getBoolean(R.styleable.FastTextView_enableLayoutCache, false);
a.recycle();
}
示例15: getDefaultTextAttribute
import android.content.Context; //导入方法依赖的package包/类
private static ColorStateList getDefaultTextAttribute(Context context, int attribute) {
Resources.Theme theme = context.getTheme();
TypedArray textAppearances = null;
try {
textAppearances = theme.obtainStyledAttributes(new int[]{attribute});
ColorStateList textColor = textAppearances.getColorStateList(0);
return textColor;
} finally {
if (textAppearances != null) {
textAppearances.recycle();
}
}
}