Java Code Examples for android.content.res.TypedArray#getDrawable()
The following examples show how to use
android.content.res.TypedArray#getDrawable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PickerFragment.java From Klyph with MIT License | 6 votes |
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.com_facebook_picker_fragment); setShowPictures(a.getBoolean(R.styleable.com_facebook_picker_fragment_show_pictures, showPictures)); String extraFieldsString = a.getString(R.styleable.com_facebook_picker_fragment_extra_fields); if (extraFieldsString != null) { String[] strings = extraFieldsString.split(","); setExtraFields(Arrays.asList(strings)); } showTitleBar = a.getBoolean(R.styleable.com_facebook_picker_fragment_show_title_bar, showTitleBar); titleText = a.getString(R.styleable.com_facebook_picker_fragment_title_text); doneButtonText = a.getString(R.styleable.com_facebook_picker_fragment_done_button_text); titleBarBackground = a.getDrawable(R.styleable.com_facebook_picker_fragment_title_bar_background); doneButtonBackground = a.getDrawable(R.styleable.com_facebook_picker_fragment_done_button_background); a.recycle(); }
Example 2
Source File: FloatingMusicMenu.java From FloatingMusicMenu with Apache License 2.0 | 6 votes |
private void initMenu(Context context, AttributeSet attrs) { TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingMusicMenu, 0, 0); progressWidthPercent = attr.getInteger(R.styleable.FloatingMusicMenu_fmm_progress_percent, 3); progressColor = attr.getColor(R.styleable.FloatingMusicMenu_fmm_progress_color, getResources().getColor(android.R.color.holo_blue_dark)); progress = attr.getFloat(R.styleable.FloatingMusicMenu_fmm_progress, 0); buttonInterval = attr.getDimension(R.styleable.FloatingMusicMenu_fmm_button_interval, 4); buttonInterval = dp2px(buttonInterval); /* if (Build.VERSION.SDK_INT < 21) { // 版本兼容 buttonInterval = -BitmapUtils.dp2px(16); }*/ cover = attr.getDrawable(R.styleable.FloatingMusicMenu_fmm_cover); backgroundTint = attr.getColorStateList(R.styleable.FloatingMusicMenu_fmm_backgroundTint); floatingDirection = attr.getInteger(R.styleable.FloatingMusicMenu_fmm_floating_direction, 0); attr.recycle(); createRootButton(context); addScrollAnimation(); }
Example 3
Source File: EaseSwitchButton.java From monolog-android with MIT License | 6 votes |
public EaseSwitchButton(Context context, AttributeSet attrs) { super(context, attrs); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.EaseSwitchButton); Drawable openDrawable = ta.getDrawable(R.styleable.EaseSwitchButton_switchOpenImage); Drawable closeDrawable = ta.getDrawable(R.styleable.EaseSwitchButton_switchCloseImage); int switchStatus = ta.getInt(R.styleable.EaseSwitchButton_switchStatus, 0); ta.recycle(); LayoutInflater.from(context).inflate(R.layout.ease_widget_switch_button, this); openImage = (ImageView) findViewById(R.id.iv_switch_open); closeImage = (ImageView) findViewById(R.id.iv_switch_close); if(openDrawable != null){ openImage.setImageDrawable(openDrawable); } if(closeDrawable != null){ closeImage.setImageDrawable(closeDrawable); } if(switchStatus == 1){ closeSwitch(); } }
Example 4
Source File: ForegroundLinearLayout.java From material-components-android with Apache License 2.0 | 6 votes |
public ForegroundLinearLayout( @NonNull Context context, @Nullable AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = ThemeEnforcement.obtainStyledAttributes( context, attrs, R.styleable.ForegroundLinearLayout, defStyle, 0); foregroundGravity = a.getInt(R.styleable.ForegroundLinearLayout_android_foregroundGravity, foregroundGravity); final Drawable d = a.getDrawable(R.styleable.ForegroundLinearLayout_android_foreground); if (d != null) { setForeground(d); } mForegroundInPadding = a.getBoolean(R.styleable.ForegroundLinearLayout_foregroundInsidePadding, true); a.recycle(); }
Example 5
Source File: ThemeUtility.java From iBeebo with GNU General Public License v3.0 | 5 votes |
public static Drawable getDrawable(int attr) { int[] attrs = new int[]{ attr }; Context context = BeeboApplication.getInstance().getActivity(); TypedArray ta = context.obtainStyledAttributes(attrs); Drawable drawable = ta.getDrawable(0); ta.recycle(); return drawable; }
Example 6
Source File: BaseActivity.java From FriendBook with GNU General Public License v3.0 | 5 votes |
public Drawable getDefaultWindowBackground() { if (mDefaultWindowBackground == null) { int[] attrsArray = {android.R.attr.windowBackground}; TypedArray typedArray = this.obtainStyledAttributes(attrsArray); mDefaultWindowBackground = typedArray.getDrawable(0); typedArray.recycle(); } return mDefaultWindowBackground; }
Example 7
Source File: ScrimInsetsRelativeLayout.java From HaoReader with GNU General Public License v3.0 | 5 votes |
private void init(Context context, AttributeSet attrs, int defStyle) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrimInsetsRelativeLayout, defStyle, 0); mInsetForeground = a.getDrawable(R.styleable.ScrimInsetsRelativeLayout_appInsetForeground); mConsumeInsets = a.getBoolean(R.styleable.ScrimInsetsRelativeLayout_appConsumeInsets, true); mFitTop = a.getBoolean(R.styleable.ScrimInsetsRelativeLayout_fitTop, true); mFitBottom = a.getBoolean(R.styleable.ScrimInsetsRelativeLayout_fitBottom, false); mFitLeft = a.getBoolean(R.styleable.ScrimInsetsRelativeLayout_fitLeft, false); mFitRight = a.getBoolean(R.styleable.ScrimInsetsRelativeLayout_fitRight, false); a.recycle(); setWillNotDraw(true); ViewCompat.setOnApplyWindowInsetsListener(this, (v, insets) -> { if (!mConsumeInsets) { if (mOnInsetsCallback != null) { mOnInsetsCallback.onInsetsChanged(new Rect(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom())); } return insets.consumeSystemWindowInsets(); } if (null == ScrimInsetsRelativeLayout.this.mInsets) { ScrimInsetsRelativeLayout.this.mInsets = new Rect(); } ScrimInsetsRelativeLayout.this.mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); ScrimInsetsRelativeLayout.this.onInsetsChanged(ScrimInsetsRelativeLayout.this.mInsets); ScrimInsetsRelativeLayout.this.setWillNotDraw(!insets.hasSystemWindowInsets() || ScrimInsetsRelativeLayout.this.mInsetForeground == null); ViewCompat.postInvalidateOnAnimation(ScrimInsetsRelativeLayout.this); return insets.consumeSystemWindowInsets(); }); }
Example 8
Source File: MyDecoration.java From SmartOrnament with Apache License 2.0 | 5 votes |
public MyDecoration(Context context, int orientation) { this.mContext = context; final TypedArray ta = context.obtainStyledAttributes(ATRRS); this.mDivider = ta.getDrawable(0); ta.recycle(); setOrientation(orientation); }
Example 9
Source File: DividerItemDecorationEx.java From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 | 5 votes |
public DividerItemDecorationEx(Context context, int orientation) { TypedArray a = context.obtainStyledAttributes(ATTRS); this.mDivider = a.getDrawable(0); if (this.mDivider == null) { Log.w("DividerItem", "@android:attr/listDivider was not set in the theme used for this DividerItemDecorationEx. Please set that attribute all call setDrawable()"); } a.recycle(); this.setOrientation(orientation); }
Example 10
Source File: DividerItemDecoration.java From Slice with Apache License 2.0 | 5 votes |
public DividerItemDecoration(Context context, float leftAdditionDp, float rightAdditionDp) { TypedArray a = context.obtainStyledAttributes(ATTRS); mDivider = a.getDrawable(0); a.recycle(); this.leftAddition = (int) (context.getResources().getDisplayMetrics().density * leftAdditionDp); this.rightAddition = (int) (context.getResources().getDisplayMetrics().density * rightAdditionDp); }
Example 11
Source File: LinePageIndicator.java From Place-Search-Service with MIT License | 5 votes |
public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return; final Resources res = getResources(); //Load defaults from resources final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color); final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color); final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width); final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width); final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width); final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0); mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered); mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth); mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth); setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth)); mPaintUnselected.setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor)); mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor)); Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
Example 12
Source File: AttrsUtils.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * attrs drawable * * @param context * @param attr * @return */ public static Drawable getTypeValueDrawable(Context context, int attr) { try { TypedValue typedValue = new TypedValue(); int[] attribute = new int[]{attr}; TypedArray array = context.obtainStyledAttributes(typedValue.resourceId, attribute); Drawable drawable = array.getDrawable(0); array.recycle(); return drawable; } catch (Exception e) { e.printStackTrace(); } return null; }
Example 13
Source File: MultiSwipeRefreshLayout.java From AndroidTabbedDialog with Apache License 2.0 | 5 votes |
public MultiSwipeRefreshLayout(Context context, AttributeSet attrs) { super(context, attrs); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MultiSwipeRefreshLayout, 0, 0); mForegroundDrawable = a.getDrawable(R.styleable.MultiSwipeRefreshLayout_foreground); if (mForegroundDrawable != null) { mForegroundDrawable.setCallback(this); setWillNotDraw(false); } a.recycle(); }
Example 14
Source File: RecycleViewDivider.java From Ticket-Analysis with MIT License | 5 votes |
/** * 默认分割线:高度为2px,颜色为灰色 * * @param context * @param orientation 列表方向 */ public RecycleViewDivider(Context context, int orientation) { if (orientation != LinearLayoutManager.VERTICAL && orientation != LinearLayoutManager.HORIZONTAL) { throw new IllegalArgumentException("请输入正确的参数!"); } mOrientation = orientation; final TypedArray a = context.obtainStyledAttributes(ATTRS); mDivider = a.getDrawable(0); a.recycle(); }
Example 15
Source File: ThemeUtil.java From materialup with Apache License 2.0 | 5 votes |
public static Drawable getThemeDrawable(Context context, int res) { Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(new int[]{res}); Drawable result = a.getDrawable(0); a.recycle(); return result; }
Example 16
Source File: NavigationDrawerContainer.java From CrimeTalk-Reader with Apache License 2.0 | 5 votes |
private void init(Context context, AttributeSet attrs, int defStyle) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrimInsetsView, defStyle, 0); if (a == null) { return; } mInsetForeground = a.getDrawable( R.styleable.ScrimInsetsView_insetForeground); a.recycle(); setWillNotDraw(true); }
Example 17
Source File: DefaultHeaderTransformer.java From AndroidPullMenu with Apache License 2.0 | 5 votes |
protected Drawable getActionBarBackground(Context context) { int[] android_styleable_ActionBar = {android.R.attr.background}; // Now get the action bar style values... TypedArray abStyle = obtainStyledAttrsFromThemeAttr(context, android.R.attr.actionBarStyle, android_styleable_ActionBar); try { // background is the first attr in the array above so it's index is 0. return abStyle.getDrawable(0); } finally { abStyle.recycle(); } }
Example 18
Source File: NiboPlacesAutoCompleteSearchView.java From Nibo with MIT License | 4 votes |
private void init(AttributeSet attrs) { setSaveEnabled(true); LayoutInflater.from(getContext()).inflate(R.layout.layout_searchview_nibo, this, true); if (attrs != null) { TypedArray attrsValue = getContext().obtainStyledAttributes(attrs, R.styleable.NiboPlacesAutoCompleteSearchView); mDisplayMode = DisplayMode.fromInt(attrsValue.getInt(R.styleable.NiboPlacesAutoCompleteSearchView_niboSV_displayMode, DisplayMode.APPBAR_MENUITEM.toInt())); mSearchCardElevation = attrsValue.getDimensionPixelSize(R.styleable.NiboPlacesAutoCompleteSearchView_niboSV_searchCardElevation, -1); mSearchTextColor = attrsValue.getColor(R.styleable.NiboPlacesAutoCompleteSearchView_niboSV_searchTextColor, Color.BLACK); mLogoDrawable = attrsValue.getDrawable(R.styleable.NiboPlacesAutoCompleteSearchView_niboSV_logoDrawable); mStringLogoDrawable = attrsValue.getString(R.styleable.NiboPlacesAutoCompleteSearchView_niboSV_logoString); mSearchEditTextColor = attrsValue.getColor(R.styleable.NiboPlacesAutoCompleteSearchView_niboSV_editTextColor, Color.BLACK); mSearchEditTextHint = attrsValue.getString(R.styleable.NiboPlacesAutoCompleteSearchView_niboSV_editHintText); mSearchEditTextHintColor = attrsValue.getColor(R.styleable.NiboPlacesAutoCompleteSearchView_niboSV_editHintTextColor, Color.BLACK); mArrorButtonColor = attrsValue.getColor(R.styleable.NiboPlacesAutoCompleteSearchView_niboSV_homeButtonColor, Color.BLACK); mCustomToolbarHeight = attrsValue.getDimensionPixelSize(R.styleable.NiboPlacesAutoCompleteSearchView_niboSV_customToolbarHeight, calculateToolbarSize(getContext())); mHomeButtonMode = attrsValue.getInt(R.styleable.NiboPlacesAutoCompleteSearchView_niboSV_homeButtonMode, 0); attrsValue.recycle(); } if (mSearchCardElevation < 0) { mSearchCardElevation = getContext().getResources().getDimensionPixelSize(R.dimen.search_card_default_card_elevation); } mCardHeight = getResources().getDimensionPixelSize(R.dimen.search_card_height); mCardVerticalPadding = (mCustomToolbarHeight - mCardHeight) / 2; switch (mDisplayMode) { case APPBAR_MENUITEM: default: mCardHorizontalPadding = getResources().getDimensionPixelSize(R.dimen.search_card_visible_padding_menu_item_mode); if (mCardVerticalPadding > mCardHorizontalPadding) mCardHorizontalPadding = mCardVerticalPadding; mHomeButtonCloseIconState = NiboHomeButton.IconState.NIBO_ARROW; mHomeButtonOpenIconState = NiboHomeButton.IconState.NIBO_ARROW; setCurrentState(SearchViewState.NORMAL); break; case SCREEN_TOOLBAR: if (mHomeButtonMode == 0) { // Arrow Mode mHomeButtonCloseIconState = NiboHomeButton.IconState.NIBO_ARROW; mHomeButtonOpenIconState = NiboHomeButton.IconState.NIBO_ARROW; } else { // Burger Mode mHomeButtonCloseIconState = NiboHomeButton.IconState.NIBO_BURGER; mHomeButtonOpenIconState = NiboHomeButton.IconState.NIBO_ARROW; } mCardHorizontalPadding = getResources().getDimensionPixelSize(R.dimen.search_card_visible_padding_toolbar_mode); setCurrentState(SearchViewState.NORMAL); break; } mHomeButtonSearchIconState = NiboHomeButton.IconState.NIBO_ARROW; bindViews(); setValuesToViews(); this.mIsMic = true; mSearchSuggestions = new ArrayList<>(); mSearchItemAdapter = new NiboBaseSearchItemAdapter(getContext(), mSearchSuggestions); mSuggestionListView.setAdapter(mSearchItemAdapter); setUpLayoutTransition(); setUpListeners(); }
Example 19
Source File: AccentQuickContactBadge.java From holoaccent with Apache License 2.0 | 4 votes |
private Drawable getOverlayDrawable(Context c) { TypedArray attr = c.obtainStyledAttributes(new int[] { R.attr.accentContactBadgeOverlay }); Drawable result = attr.getDrawable(0); attr.recycle(); return result; }
Example 20
Source File: SuggestionStripView.java From Indic-Keyboard with Apache License 2.0 | 4 votes |
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); mImportantNoticeStrip = findViewById(R.id.important_notice_strip); mStripVisibilityGroup = new StripVisibilityGroup(this, mSuggestionsStrip, mImportantNoticeStrip); for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) { final TextView word = new TextView(context, null, R.attr.suggestionWordStyle); word.setContentDescription(getResources().getString(R.string.spoken_empty_suggestion)); 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); }