List of usage examples for android.content Context obtainStyledAttributes
public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes)
From source file:android.support.v7.internal.widget.ViewUtils.java
/** * Allows us to emulate the {@code android:theme} attribute for devices before L. *//* w w w. j a va 2 s . c o m*/ public static Context themifyContext(Context context, AttributeSet attrs, boolean useAndroidTheme, boolean useAppTheme) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.View, 0, 0); int themeId = 0; if (useAndroidTheme) { // First try reading android:theme if enabled themeId = a.getResourceId(R.styleable.View_android_theme, 0); } if (useAppTheme && themeId == 0) { // ...if that didn't work, try reading app:theme (for legacy reasons) if enabled themeId = a.getResourceId(R.styleable.View_theme, 0); if (themeId != 0) { Log.i(TAG, "app:theme is now deprecated. Please move to using android:theme instead."); } } a.recycle(); if (themeId != 0 && (!(context instanceof ContextThemeWrapper) || ((ContextThemeWrapper) context).getThemeResId() != themeId)) { // If the context isn't a ContextThemeWrapperCompat, or it is but does not have // the same theme as we need, wrap it in a new wrapper context = new ContextThemeWrapper(context, themeId); } return context; }
From source file:android.support.v7.widget.TintTypedArray.java
public static TintTypedArray obtainStyledAttributes(Context context, AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { return new TintTypedArray(context, context.obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes)); }
From source file:android.support.v7.app.AppCompatViewInflater.java
/** * Allows us to emulate the {@code android:theme} attribute for devices before L. *//*from www .ja v a 2 s . c o m*/ private static Context themifyContext(Context context, AttributeSet attrs, boolean useAndroidTheme, boolean useAppTheme) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.View, 0, 0); int themeId = 0; if (useAndroidTheme) { // First try reading android:theme if enabled themeId = a.getResourceId(R.styleable.View_android_theme, 0); } if (useAppTheme && themeId == 0) { // ...if that didn't work, try reading app:theme (for legacy reasons) if enabled themeId = a.getResourceId(R.styleable.View_theme, 0); if (themeId != 0) { Log.i(LOG_TAG, "app:theme is now deprecated. " + "Please move to using android:theme instead."); } } a.recycle(); if (themeId != 0 && (!(context instanceof ContextThemeWrapper) || ((ContextThemeWrapper) context).getThemeResId() != themeId)) { // If the context isn't a ContextThemeWrapper, or it is but does not have // the same theme as we need, wrap it in a new wrapper context = new ContextThemeWrapper(context, themeId); } return context; }
From source file:android.support.v7ox.app.AppCompatViewInflater.java
/** * Allows us to emulate the {@code android:theme} attribute for devices before L. *//*from ww w . j av a2 s .co m*/ private static Context themifyContext(Context context, AttributeSet attrs, boolean useAndroidTheme, boolean useAppTheme) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.View, 0, 0); int themeId = 0; if (useAndroidTheme) { // First try reading android:theme if enabled themeId = a.getResourceId(R.styleable.View_android_theme, 0); } if (useAppTheme && themeId == 0) { // ...if that didn't work, try reading app:theme (for legacy reasons) if enabled themeId = a.getResourceId(R.styleable.View_theme_ox, 0); if (themeId != 0) { Log.i(LOG_TAG, "app:theme is now deprecated. " + "Please move to using android:theme instead."); } } a.recycle(); if (themeId != 0 && (!(context instanceof ContextThemeWrapper) || ((ContextThemeWrapper) context).getThemeResId() != themeId)) { // If the context isn't a ContextThemeWrapper, or it is but does not have // the same theme as we need, wrap it in a new wrapper context = new ContextThemeWrapper(context, themeId); } return context; }
From source file:de.vanita5.twittnuker.util.ThemeUtils.java
public static int getTitleTextAppearance(final Context context) { final TypedArray a = context.obtainStyledAttributes(null, new int[] { android.R.attr.titleTextStyle }, android.R.attr.actionBarStyle, android.R.style.Widget_Holo_ActionBar); final int textAppearance = a.getResourceId(0, android.R.style.TextAppearance_Holo); a.recycle();/*from ww w .ja va 2 s . c o m*/ return textAppearance; }
From source file:de.vanita5.twittnuker.util.ThemeUtils.java
public static Drawable getActionBarBackground(final Context context, final int themeRes) { final TypedArray a = context.obtainStyledAttributes(null, new int[] { android.R.attr.background }, android.R.attr.actionBarStyle, themeRes); final Drawable d = a.getDrawable(0); a.recycle();/*from w w w . j a va2 s. c o m*/ return applyActionBarDrawable(context, d, isTransparentBackground(themeRes)); }
From source file:de.vanita5.twittnuker.util.ThemeUtils.java
public static Drawable getActionBarSplitBackground(final Context context, final int themeRes) { final TypedArray a = context.obtainStyledAttributes(null, new int[] { android.R.attr.backgroundSplit }, android.R.attr.actionBarStyle, themeRes); final Drawable d = a.getDrawable(0); a.recycle();/*from w ww . j a v a2s . com*/ return applyActionBarDrawable(context, d, isTransparentBackground(themeRes)); }
From source file:de.vanita5.twittnuker.util.ThemeUtils.java
public static Drawable getActionBarStackedBackground(final Context context, final int themeRes) { final TypedArray a = context.obtainStyledAttributes(null, new int[] { android.R.attr.backgroundStacked }, android.R.attr.actionBarStyle, themeRes); final Drawable d = a.getDrawable(0); a.recycle();//from w w w . ja va 2 s.com return applyActionBarDrawable(context, d, isTransparentBackground(themeRes)); }
From source file:de.vanita5.twittnuker.util.ThemeUtils.java
public static Drawable getWindowBackground(final Context context, final int themeRes) { final TypedArray a = context.obtainStyledAttributes(null, new int[] { android.R.attr.windowBackground }, 0, themeRes);//from w w w. j a v a2s . c o m final Drawable d = a.getDrawable(0); a.recycle(); if (isTransparentBackground(themeRes)) { applyThemeBackgroundAlphaToDrawable(context, d); } return d; }
From source file:de.vanita5.twittnuker.util.ThemeUtils.java
@Deprecated public static Drawable getActionBarBackground(final Context context, final boolean applyAlpha) { final TypedArray a = context.obtainStyledAttributes(null, new int[] { android.R.attr.background }, android.R.attr.actionBarStyle, 0); final Drawable d = a.getDrawable(0); a.recycle();//from w ww . j a v a2s .c o m return applyActionBarDrawable(context, d, applyAlpha); }