Example usage for android.content.res TypedArray getDrawable

List of usage examples for android.content.res TypedArray getDrawable

Introduction

In this page you can find the example usage for android.content.res TypedArray getDrawable.

Prototype

@Nullable
public Drawable getDrawable(@StyleableRes int index) 

Source Link

Document

Retrieve the Drawable for the attribute at index.

Usage

From source file:com.android.yijiang.kzx.widget.tab.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs) {
    super(context, attrs);
    setHorizontalScrollBarEnabled(false); //??????

    if (attrs != null) {
        TypedArray attrsTypedArray = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
        if (attrsTypedArray != null) {
            allowWidthFull = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_allowWidthFull, false);
            slidingBlockDrawable = attrsTypedArray.getDrawable(R.styleable.PagerSlidingTabStrip_slidingBlock);
            attrsTypedArray.recycle();/*w  w  w  . j  av a  2 s .c  o  m*/
        }
    }
}

From source file:com.aosijia.dragonbutler.ui.widget.ActionSheet.java

private Attributes readAttribute() {
    Attributes attrs = new Attributes(getActivity());
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(null, R.styleable.ActionSheet,
            R.attr.actionSheetStyle, 0);
    Drawable background = a.getDrawable(R.styleable.ActionSheet_actionSheetBackground);
    if (background != null) {
        attrs.background = background;/* www  .  j  av a  2 s .  co  m*/
    }
    Drawable cancelButtonBackground = a.getDrawable(R.styleable.ActionSheet_cancelButtonBackground);
    if (cancelButtonBackground != null) {
        attrs.cancelButtonBackground = cancelButtonBackground;
    }
    Drawable otherButtonTopBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonTopBackground);
    if (otherButtonTopBackground != null) {
        attrs.otherButtonTopBackground = otherButtonTopBackground;
    }
    Drawable otherButtonMiddleBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonMiddleBackground);
    if (otherButtonMiddleBackground != null) {
        attrs.otherButtonMiddleBackground = otherButtonMiddleBackground;
    }
    Drawable otherButtonBottomBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonBottomBackground);
    if (otherButtonBottomBackground != null) {
        attrs.otherButtonBottomBackground = otherButtonBottomBackground;
    }
    Drawable otherButtonSingleBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonSingleBackground);
    if (otherButtonSingleBackground != null) {
        attrs.otherButtonSingleBackground = otherButtonSingleBackground;
    }
    attrs.cancelButtonTextColor = a.getColor(R.styleable.ActionSheet_cancelButtonTextColor,
            attrs.cancelButtonTextColor);
    attrs.otherButtonTextColor = a.getColor(R.styleable.ActionSheet_otherButtonTextColor,
            attrs.otherButtonTextColor);
    attrs.padding = (int) a.getDimension(R.styleable.ActionSheet_actionSheetPadding, attrs.padding);
    attrs.otherButtonSpacing = (int) a.getDimension(R.styleable.ActionSheet_otherButtonSpacing,
            attrs.otherButtonSpacing);
    attrs.cancelButtonMarginTop = (int) a.getDimension(R.styleable.ActionSheet_cancelButtonMarginTop,
            attrs.cancelButtonMarginTop);
    attrs.actionSheetTextSize = a.getDimensionPixelSize(R.styleable.ActionSheet_actionSheetTextSize,
            (int) attrs.actionSheetTextSize);

    a.recycle();
    return attrs;
}

From source file:com.mobiletin.inputmethod.indic.suggestions.SuggestionStripView.java

public SuggestionStripView(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    final LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.suggestions_strip, this);

    mSuggestionsStrip = (ViewGroup) findViewById(R.id.suggestions_strip);
    mVoiceKey = (ImageButton) findViewById(R.id.suggestions_strip_voice_key);
    mAddToDictionaryStrip = (ViewGroup) findViewById(R.id.add_to_dictionary_strip);
    mImportantNoticeStrip = findViewById(R.id.important_notice_strip);
    mStripVisibilityGroup = new StripVisibilityGroup(this, mSuggestionsStrip, mAddToDictionaryStrip,
            mImportantNoticeStrip);/*from   w w w .j a  v  a 2s .c o m*/

    for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
        final TextView word = new TextView(context, null, R.attr.suggestionWordStyle);
        word.setOnClickListener(this);
        word.setOnLongClickListener(this);
        mWordViews.add(word);
        final View divider = inflater.inflate(R.layout.suggestion_divider, null);
        mDividerViews.add(divider);
        final TextView info = new TextView(context, null, R.attr.suggestionWordStyle);
        info.setTextColor(Color.WHITE);
        info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEBUG_INFO_TEXT_SIZE_IN_DIP);
        mDebugInfoViews.add(info);
    }

    mLayoutHelper = new SuggestionStripLayoutHelper(context, attrs, defStyle, mWordViews, mDividerViews,
            mDebugInfoViews);

    mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null);
    mMoreSuggestionsView = (MoreSuggestionsView) mMoreSuggestionsContainer
            .findViewById(R.id.more_suggestions_view);
    mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView);

    final Resources res = context.getResources();
    mMoreSuggestionsModalTolerance = res
            .getDimensionPixelOffset(R.dimen.config_more_suggestions_modal_tolerance);
    mMoreSuggestionsSlidingDetector = new GestureDetector(context, mMoreSuggestionsSlidingListener);

    final TypedArray keyboardAttr = context.obtainStyledAttributes(attrs, R.styleable.Keyboard, defStyle,
            R.style.SuggestionStripView);
    final Drawable iconVoice = keyboardAttr.getDrawable(R.styleable.Keyboard_iconShortcutKey);
    keyboardAttr.recycle();
    mVoiceKey.setImageDrawable(iconVoice);
    mVoiceKey.setOnClickListener(this);
}

From source file:com.efan.notlonely_android.view.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs) {
    super(context, attrs);
    setHorizontalScrollBarEnabled(false); //
    removeAllViews();/*from w ww . j a v  a 2  s .  c om*/
    if (attrs != null) {
        TypedArray attrsTypedArray = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
        if (attrsTypedArray != null) {
            allowWidthFull = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_allowWidthFull, false);
            slidingBlockDrawable = attrsTypedArray.getDrawable(R.styleable.PagerSlidingTabStrip_slidingBlock);
            disableViewPager = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_disableViewPager,
                    false);
            disableTensileSlidingBlock = attrsTypedArray
                    .getBoolean(R.styleable.PagerSlidingTabStrip_disableTensileSlidingBlock, false);
            attrsTypedArray.recycle();
        }
    }
}

From source file:com.appeaser.sublimenavigationviewlibrary.SublimeThemer.java

private Drawable obtainSelectableItemBackground() {
    // Create an array of the attributes we want to resolve
    int[] attrs = new int[] { R.attr.selectableItemBackground }; // index 0

    // Obtain the styled attributes
    TypedArray ta = mContext.obtainStyledAttributes(attrs);

    Drawable drawableFromTheme = null;//from  w ww  .  jav  a  2s .  c o m

    if (ta.hasValue(0)) {
        // Get the value of the 'selectableItemBackground' attribute that was
        // set in the theme. The parameter is the index
        // of the attribute in the 'attrs' array.
        drawableFromTheme = ta.getDrawable(0); // index
    }

    // Finally free resources used by TypedArray
    ta.recycle();

    return drawableFromTheme;
}

From source file:com.cjj.viewpagerlibrary.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs) {
    super(context, attrs);
    setHorizontalScrollBarEnabled(false); //??????

    if (attrs != null) {
        TypedArray attrsTypedArray = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
        if (attrsTypedArray != null) {
            allowWidthFull = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_allowWidthFull, false);
            slidingBlockDrawable = attrsTypedArray.getDrawable(R.styleable.PagerSlidingTabStrip_slidingBlock);
            disableViewPager = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_disableViewPager,
                    false);/*w  w  w  .j  a v  a  2  s .  c  om*/
            attrsTypedArray.recycle();
        }
    }
}

From source file:com.example.administrator.smartbj.Drawer.MyNavigationView.java

public MyNavigationView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    //        ThemeUtils.checkAppCompatTheme(context);

    // Create the menu
    mMenu = new MyNavigationMenu2(context);

    // Custom attributes
    TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.NavigationView,
            defStyleAttr, android.support.design.R.style.Widget_Design_NavigationView);

    //noinspection deprecation
    setBackgroundDrawable(a.getDrawable(android.support.design.R.styleable.NavigationView_android_background));
    if (a.hasValue(android.support.design.R.styleable.NavigationView_elevation)) {
        ViewCompat.setElevation(this,
                a.getDimensionPixelSize(android.support.design.R.styleable.NavigationView_elevation, 0));
    }/*from w  w w  . j a v  a  2 s .c  o  m*/
    ViewCompat.setFitsSystemWindows(this,
            a.getBoolean(android.support.design.R.styleable.NavigationView_android_fitsSystemWindows, false));

    mMaxWidth = a.getDimensionPixelSize(android.support.design.R.styleable.NavigationView_android_maxWidth, 0);

    final ColorStateList itemIconTint;
    if (a.hasValue(android.support.design.R.styleable.NavigationView_itemIconTint)) {
        itemIconTint = a.getColorStateList(android.support.design.R.styleable.NavigationView_itemIconTint);
    } else {
        itemIconTint = createDefaultColorStateList(android.R.attr.textColorSecondary);
    }

    boolean textAppearanceSet = false;
    int textAppearance = 0;
    if (a.hasValue(android.support.design.R.styleable.NavigationView_itemTextAppearance)) {
        textAppearance = a.getResourceId(android.support.design.R.styleable.NavigationView_itemTextAppearance,
                0);
        textAppearanceSet = true;
    }

    ColorStateList itemTextColor = null;
    if (a.hasValue(android.support.design.R.styleable.NavigationView_itemTextColor)) {
        itemTextColor = a.getColorStateList(android.support.design.R.styleable.NavigationView_itemTextColor);
    }

    if (!textAppearanceSet && itemTextColor == null) {
        // If there isn't a text appearance set, we'll use a default text color
        itemTextColor = createDefaultColorStateList(android.R.attr.textColorPrimary);
    }

    final Drawable itemBackground = a
            .getDrawable(android.support.design.R.styleable.NavigationView_itemBackground);

    mMenu.setCallback(new MenuBuilder.Callback() {
        @Override
        public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
            return mListener != null && mListener.onNavigationItemSelected(item);
        }

        @Override
        public void onMenuModeChange(MenuBuilder menu) {
        }
    });
    mPresenter.setId(PRESENTER_NAVIGATION_VIEW_ID);
    mPresenter.initForMenu(context, mMenu);
    mPresenter.setItemIconTintList(itemIconTint);
    if (textAppearanceSet) {
        mPresenter.setItemTextAppearance(textAppearance);
    }
    mPresenter.setItemTextColor(itemTextColor);
    mPresenter.setItemBackground(itemBackground);
    mMenu.addMenuPresenter(mPresenter);
    addView((View) mPresenter.getMenuView(this));

    if (a.hasValue(android.support.design.R.styleable.NavigationView_menu)) {
        inflateMenu(a.getResourceId(android.support.design.R.styleable.NavigationView_menu, 0));
    }

    if (a.hasValue(android.support.design.R.styleable.NavigationView_headerLayout)) {
        inflateHeaderView(a.getResourceId(android.support.design.R.styleable.NavigationView_headerLayout, 0));
    }

    a.recycle();
}

From source file:com.astuetz.viewpager.extensions.ScrollingTabsView.java

public ScrollingTabsView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);

    this.mContext = context;

    mDividerMarginTop = (int) (getResources().getDisplayMetrics().density * mDividerMarginTop);
    mDividerMarginBottom = (int) (getResources().getDisplayMetrics().density * mDividerMarginBottom);
    mDividerWidth = (int) (getResources().getDisplayMetrics().density * mDividerWidth);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerExtensions, defStyle, 0);

    mDividerColor = a.getColor(R.styleable.ViewPagerExtensions_dividerColor, mDividerColor);

    mDividerMarginTop = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginTop,
            mDividerMarginTop);//from  ww  w  .  ja  v  a 2 s  .co  m
    mDividerMarginBottom = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginBottom,
            mDividerMarginBottom);

    mDividerDrawable = a.getDrawable(R.styleable.ViewPagerExtensions_dividerDrawable);

    a.recycle();

    this.setHorizontalScrollBarEnabled(false);
    this.setHorizontalFadingEdgeEnabled(false);

    mContainer = new LinearLayout(context);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT);
    mContainer.setLayoutParams(params);
    mContainer.setOrientation(LinearLayout.HORIZONTAL);

    this.addView(mContainer);

}

From source file:com.ereader.client.ui.view.TabsView.java

public TabsView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);

    this.mContext = context;

    mDividerMarginTop = (int) (getResources().getDisplayMetrics().density * mDividerMarginTop);
    mDividerMarginBottom = (int) (getResources().getDisplayMetrics().density * mDividerMarginBottom);
    mDividerWidth = (int) (getResources().getDisplayMetrics().density * mDividerWidth);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerExtensions, defStyle, 0);

    mDividerColor = a.getColor(R.styleable.ViewPagerExtensions_dividerColor, mDividerColor);

    mDividerMarginTop = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginTop,
            mDividerMarginTop);/*from  w w  w  .j  a v a  2s . c o m*/
    mDividerMarginBottom = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginBottom,
            mDividerMarginBottom);

    mDividerDrawable = a.getDrawable(R.styleable.ViewPagerExtensions_dividerDrawable);

    a.recycle();

    this.setHorizontalScrollBarEnabled(false);
    this.setHorizontalFadingEdgeEnabled(false);

    mContainer = new LinearLayout(context);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mContainer.setLayoutParams(params);
    mContainer.setOrientation(LinearLayout.HORIZONTAL);
    mContainer.setGravity(Gravity.CENTER);
    this.addView(mContainer);

}

From source file:com.ereader.client.ui.view.ScrollingTabsView.java

public ScrollingTabsView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);

    this.mContext = context;

    mDividerMarginTop = (int) (getResources().getDisplayMetrics().density * mDividerMarginTop);
    mDividerMarginBottom = (int) (getResources().getDisplayMetrics().density * mDividerMarginBottom);
    mDividerWidth = (int) (getResources().getDisplayMetrics().density * mDividerWidth);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerExtensions, defStyle, 0);

    mDividerColor = a.getColor(R.styleable.ViewPagerExtensions_dividerColor, mDividerColor);

    mDividerMarginTop = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginTop,
            mDividerMarginTop);//  w ww.j  a  v a 2 s. c  om
    mDividerMarginBottom = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginBottom,
            mDividerMarginBottom);

    mDividerDrawable = a.getDrawable(R.styleable.ViewPagerExtensions_dividerDrawable);

    a.recycle();

    this.setHorizontalScrollBarEnabled(false);
    this.setHorizontalFadingEdgeEnabled(false);

    mContainer = new LinearLayout(context);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    mContainer.setLayoutParams(params);
    mContainer.setOrientation(LinearLayout.HORIZONTAL);
    mContainer.setGravity(Gravity.CENTER);
    this.addView(mContainer);

}