Example usage for android.content Context getTheme

List of usage examples for android.content Context getTheme

Introduction

In this page you can find the example usage for android.content Context getTheme.

Prototype

@ViewDebug.ExportedProperty(deepExport = true)
public abstract Resources.Theme getTheme();

Source Link

Document

Return the Theme object associated with this Context.

Usage

From source file:Main.java

public static int getEditTextColor(Context ctx) {
    TypedValue tv = new TypedValue();
    boolean found = ctx.getTheme().resolveAttribute(android.R.attr.editTextColor, tv, true);
    if (found) {// ww w  . j a  va2s  . co m
        // SDK 11+
        return ctx.getResources().getColor(tv.resourceId);
    } else {
        // SDK < 11
        return ctx.getResources().getColor(android.R.color.primary_text_light);
    }
}

From source file:Main.java

public static int getAttributeColor(Context context, int attributeId) {
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(attributeId, typedValue, true);
    return context.getResources().getColor(typedValue.resourceId);
}

From source file:Main.java

public static int getActionBarSize(Context context) {
    TypedValue tv = new TypedValue();
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        int actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                context.getResources().getDisplayMetrics());
        return actionBarHeight;
    }/*from w  w w . j  ava 2 s.c  o m*/
    return 0;
}

From source file:Main.java

@Nullable
public static Drawable getAttributeDrawable(Context context, int attributeId) {
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(attributeId, typedValue, true);
    return context.getResources().getDrawable(typedValue.resourceId);
}

From source file:Main.java

public static int getThemeColor(Context ctx, int attr) {
    TypedValue tv = new TypedValue();
    if (ctx.getTheme().resolveAttribute(attr, tv, true)) {
        return tv.data;
    }/*from ww  w.  java2 s . c  o  m*/
    return 0;
}

From source file:Main.java

public static String getColorFromThemeInHex(Context context, int resourceId) {
    TypedValue typedvalueattr = new TypedValue();
    context.getTheme().resolveAttribute(resourceId, typedvalueattr, true);
    return String.format("#%06X", (0xFFFFFF & context.getResources().getColor(typedvalueattr.resourceId)));
}

From source file:Main.java

public static TypedValue resolveThemeAttribute(Context context, int attrId) {
    TypedValue value = new TypedValue();
    context.getTheme().resolveAttribute(attrId, value, true);
    return value;
}

From source file:Main.java

public static int getActionBarHeight(Context c) {

    int mActionBarSize;

    final TypedArray styledAttributes = c.getTheme()
            .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
    mActionBarSize = (int) styledAttributes.getDimension(0, 0);
    styledAttributes.recycle();//w w w .  jav a2s  .c om

    return mActionBarSize;

}

From source file:Main.java

public static float getDimension(Context context, @StyleRes int styleResId, @AttrRes int attr) {
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(styleResId, new int[] { attr });
    float size = typedArray.getDimension(0, 0);
    typedArray.recycle();/*from  www  .j  a  va  2s  .co  m*/
    return size;
}

From source file:Main.java

public static int getThemeColor(Context context, @AttrRes final int id) {
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(id, typedValue, true);
    return typedValue.data;
}