當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。