当前位置: 首页>>代码示例>>Java>>正文


Java Context.getTheme方法代码示例

本文整理汇总了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;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:29,代码来源:FoldableLinearLayout.java

示例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();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:CalligraphyUtils.java

示例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;
}
 
开发者ID:sfilmak,项目名称:MakiLite,代码行数:17,代码来源:ThemeUtils.java

示例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;
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:17,代码来源:ResourcesUtils.java

示例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);
	}
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:19,代码来源:FontWidgetDecorator.java

示例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;
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:34,代码来源:ActionButton.java

示例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;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:21,代码来源:UIUtils.java

示例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;
}
 
开发者ID:1313ou,项目名称:TreebolicLib,代码行数:23,代码来源:Utils.java

示例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);
  }
}
 
开发者ID:seven332,项目名称:Stage,代码行数:27,代码来源:DialogContentView.java

示例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);
    }
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:21,代码来源:ColorTextView.java

示例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;
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:8,代码来源:ViewHelper.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:34,代码来源:AppCompatDelegateImplV7.java

示例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);
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:36,代码来源:ReactToolbarManager.java

示例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();
}
 
开发者ID:lsjwzh,项目名称:FastTextView,代码行数:14,代码来源:FastTextView.java

示例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();
    }
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:14,代码来源:DefaultStyleValuesUtil.java


注:本文中的android.content.Context.getTheme方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。