resolve Boolean value from Context - Android android.content

Android examples for android.content:Context

Description

resolve Boolean value from Context

Demo Code


//package com.java2s;
import android.content.Context;

import android.content.res.TypedArray;

import android.support.annotation.AttrRes;

public class Main {
    public static boolean resolveBoolean(Context context,
            @AttrRes int attr, boolean fallback) {
        TypedArray a = context.getTheme().obtainStyledAttributes(
                new int[] { attr });
        try {/*from   www. j  av  a  2s .  com*/
            return a.getBoolean(0, fallback);
        } finally {
            a.recycle();
        }
    }

    public static boolean resolveBoolean(Context context, @AttrRes int attr) {
        return resolveBoolean(context, attr, false);
    }
}

Related Tutorials