Retrieve the selectable background of the current style for View. - Android User Interface

Android examples for User Interface:View Background

Description

Retrieve the selectable background of the current style for View.

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.TypedValue;

public class Main {
    /**/*  w w w.  java 2  s . co m*/
     * Retrieve the selectable background of the current style.
     *
     * @param context context used to retrieve the styled attributes.
     * @return selectable item background res id.
     */
    public static int getSelectableItemBackground(Context context) {
        int selectableItemBackgroundResId;
        int[] attrs = new int[] { android.R.attr.selectableItemBackground };
        TypedValue values = new TypedValue();
        TypedArray array = context.obtainStyledAttributes(values.data,
                attrs);
        selectableItemBackgroundResId = array.getResourceId(0, 0);
        array.recycle();
        return selectableItemBackgroundResId;
    }
}

Related Tutorials