Java Code Examples for android.graphics.drawable.GradientDrawable#setColor()
The following examples show how to use
android.graphics.drawable.GradientDrawable#setColor() .
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: SelectorDrawableCreator.java From BackgroundLibrary with Apache License 2.0 | 6 votes |
private void setSelectorDrawable(TypedArray typedArray, TypedArray selectorTa, StateListDrawable stateListDrawable, int attr, @AttrRes int functionId) throws Exception { int color = 0; Drawable resDrawable = null; //这里用try catch先判断是否是颜色而不是直接调用getDrawable,为了方便填入的是颜色时可以沿用其他属性, //否则如果是其他资源会覆盖app:corners_radius等其他shape属性设置的效果 try { color = selectorTa.getColor(attr, 0); if (color == 0) { resDrawable = selectorTa.getDrawable(attr); } } catch (Exception e) { resDrawable = selectorTa.getDrawable(attr); } if (resDrawable == null && color != 0) { GradientDrawable tmpDrawable = DrawableFactory.getDrawable(typedArray); tmpDrawable.setColor(color); stateListDrawable.addState(new int[]{functionId}, tmpDrawable); } else { stateListDrawable.addState(new int[]{functionId}, resDrawable); } }
Example 2
Source File: Switch.java From XERUNG with Apache License 2.0 | 6 votes |
public void changeBackground() { if (iSchecked) { if (!isInEditMode()) { setBackgroundResource(R.drawable.background_checkbox); LayerDrawable layer = (LayerDrawable) getBackground(); GradientDrawable shape = (GradientDrawable) layer .findDrawableByLayerId(R.id.shape_bacground); shape.setColor(backgroundColor); } } else { if (!isInEditMode()) { setBackgroundResource(R.drawable.background_switch_ball_uncheck); } } }
Example 3
Source File: ButtonDrawableCreator.java From BackgroundLibrary with Apache License 2.0 | 6 votes |
private void setSelectorDrawable(TypedArray typedArray, TypedArray buttonTa, StateListDrawable stateListDrawable, int attr, @AttrRes int functionId) throws Exception { int color = 0; Drawable resDrawable = null; //这里用try catch先判断是否是颜色而不是直接调用getDrawable,为了方便填入的是颜色时可以沿用其他属性, //否则如果是其他资源会覆盖app:corners_radius等其他shape属性设置的效果 try { color = buttonTa.getColor(attr, 0); if (color == 0) { resDrawable = buttonTa.getDrawable(attr); } } catch (Exception e) { resDrawable = buttonTa.getDrawable(attr); } if (resDrawable == null && color != 0) { GradientDrawable tmpDrawable = DrawableFactory.getDrawable(typedArray); tmpDrawable.setColor(color); stateListDrawable.addState(new int[]{functionId}, tmpDrawable); } else { stateListDrawable.addState(new int[]{functionId}, resDrawable); } }
Example 4
Source File: RecyclerViewBanner.java From RecyclerViewBanner with Apache License 2.0 | 5 votes |
/** * 默认指示器是一系列直径为6dp的小圆点 */ private GradientDrawable generateDefaultDrawable(int color) { GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setSize(dp2px(6), dp2px(6)); gradientDrawable.setCornerRadius(dp2px(6)); gradientDrawable.setColor(color); return gradientDrawable; }
Example 5
Source File: MyDrawable.java From SuperNote with GNU General Public License v3.0 | 5 votes |
public static GradientDrawable getIcFolderSelectedDrawable( int color){ GradientDrawable gradientDrawable=new GradientDrawable(); gradientDrawable.setShape(GradientDrawable.OVAL); gradientDrawable.setSize(SizeUtils.dp2px(24), SizeUtils.dp2px(24)); gradientDrawable.setBounds(0,0,SizeUtils.dp2px(24), SizeUtils.dp2px(24)); gradientDrawable.setColor(color); return gradientDrawable; }
Example 6
Source File: ColorDecorator.java From monthweekmaterialcalendarview with Apache License 2.0 | 5 votes |
@Override public void decorate(DayViewFacade view) { int selectcolor=color; GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadius(32); drawable.setColor(selectcolor); drawable.setStroke(1, selectcolor); view.setSelectionDrawable(drawable); }
Example 7
Source File: ItemDecorationDivider.java From DanDanPlayForAndroid with MIT License | 5 votes |
public ItemDecorationDivider(int dividerWidthPx, @ColorInt int dividerColor, int spanCount) { GradientDrawable shapeDrawable = new GradientDrawable(); shapeDrawable.setColor(dividerColor); shapeDrawable.setShape(GradientDrawable.RECTANGLE); shapeDrawable.setSize(dividerWidthPx, dividerWidthPx); this.mCount = spanCount; this.mLineWidth = dividerWidthPx; this.mDivider = shapeDrawable; }
Example 8
Source File: BackgroundHelper.java From monero-wallet-android-app with MIT License | 5 votes |
public static Drawable getRedDotDrawable(Context context) { GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setShape(GradientDrawable.OVAL); gradientDrawable.setColor(ContextCompat.getColor(context, R.color.color_FF3A5C)); gradientDrawable.setSize(DisplayHelper.dpToPx(9), DisplayHelper.dpToPx(9)); return gradientDrawable; }
Example 9
Source File: QuickConversationAdapter.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void processContactImage(Contact contact, TextView textView, TextView alphabeticTextView, CircleImageView contactImage) { try { String contactNumber = ""; char firstLetter = 0; contactNumber = contact.getDisplayName().toUpperCase(); firstLetter = contact.getDisplayName().toUpperCase().charAt(0); if (contact != null) { if (firstLetter != '+') { alphabeticTextView.setText(String.valueOf(firstLetter)); } else if (contactNumber.length() >= 2) { alphabeticTextView.setText(String.valueOf(contactNumber.charAt(1))); } Character colorKey = AlphaNumberColorUtil.alphabetBackgroundColorMap.containsKey(firstLetter) ? firstLetter : null; GradientDrawable bgShape = (GradientDrawable) alphabeticTextView.getBackground(); bgShape.setColor(ApplozicService.getContext(context).getResources().getColor(AlphaNumberColorUtil.alphabetBackgroundColorMap.get(colorKey))); } alphabeticTextView.setVisibility(View.GONE); contactImage.setVisibility(View.VISIBLE); if (contact != null) { if (contact.isDrawableResources()) { int drawableResourceId = ApplozicService.getContext(context).getResources().getIdentifier(contact.getrDrawableName(), "drawable", ApplozicService.getContext(context).getPackageName()); contactImage.setImageResource(drawableResourceId); } else { contactImageLoader.loadImage(contact, contactImage, alphabeticTextView); } } textView.setVisibility(contact != null && contact.isOnline() ? View.VISIBLE : View.GONE); } catch (Exception e) { } }
Example 10
Source File: BadgeDialogFactory.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
private void setBackground(ImageView view, int color) { GradientDrawable shape = new GradientDrawable(); shape.setShape(GradientDrawable.OVAL); shape.setColor(color); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { view.setBackground(shape); } else { view.setBackgroundDrawable(shape); } }
Example 11
Source File: Shape.java From SelectorDrawable with Apache License 2.0 | 5 votes |
public GradientDrawable createGradientDrawable(@ColorInt int color) { GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadius(mCorner); drawable.setColor(color); drawable.setStroke(mStrokeWidth, mStrokeColor); if (mCorner == 0) { drawable.setCornerRadii(new float[]{mLeftTopCorner, mLeftTopCorner, mRightTopCorner, mRightTopCorner, mRightBottomCorner, mRightBottomCorner, mLeftBottomCorner, mLeftBottomCorner}); } return drawable; }
Example 12
Source File: VoicePlayerView.java From ChatVoicePlayer with MIT License | 5 votes |
public void setPlayPaueseBackgroundShape(int color, float radius){ GradientDrawable shape = new GradientDrawable(); shape.setColor(getResources().getColor(color)); shape.setCornerRadius(radius); imgPause.setBackground(shape); imgPlay.setBackground(shape); }
Example 13
Source File: RadiusTextDelegate.java From UIWidget with Apache License 2.0 | 5 votes |
/** * 获取不同状态下的Drawable信息 * * @param drawable * @param radius * @param width * @param height * @return */ protected Drawable getStateDrawable(Drawable drawable, float radius, int width, int height) { if (drawable == null) return drawable; if (drawable instanceof ColorDrawable) { ColorDrawable colorDrawable = (ColorDrawable) drawable; GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setColor(colorDrawable.getColor()); gradientDrawable.setCornerRadius(radius); gradientDrawable.setSize(width, height); drawable = gradientDrawable; } DrawableUtil.setDrawableWidthHeight(drawable, width, height); return drawable; }
Example 14
Source File: PagerOptions.java From BannerPager with Apache License 2.0 | 5 votes |
private Drawable createDrawable(@ColorInt int color) { final int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, mContext.getResources().getDisplayMetrics()); final GradientDrawable gd = new GradientDrawable(); gd.setColor(color); gd.setShape(GradientDrawable.OVAL); gd.setSize(size, size); return gd; }
Example 15
Source File: AchievementView.java From AchievementView with Apache License 2.0 | 5 votes |
/** * Metodo seta forma retangular no achievement * @return */ @Override public AchievementListern setBorderRetangle(){ ll_content_main.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.retangle_archiement)); GradientDrawable bgView = (GradientDrawable)ll_content_main.getBackground(); bgView.setColor(context.getResources().getColor(color)); return this; }
Example 16
Source File: Switch.java From MaterialDesignLibrary with Apache License 2.0 | 5 votes |
public void changeBackground() { if (eventCheck) { setBackgroundResource(R.drawable.background_checkbox); LayerDrawable layer = (LayerDrawable) getBackground(); GradientDrawable shape = (GradientDrawable) layer .findDrawableByLayerId(R.id.shape_bacground); shape.setColor(backgroundColor); } else { setBackgroundResource(R.drawable.background_switch_ball_uncheck); } }
Example 17
Source File: ColorChooserPreferenceX.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
Drawable createSelector(int color) { int position = -1; for (int i = 0; i < mColors.length; i++) { if (mColors[i] == color) { position = i; break; } } String applicationTheme = ApplicationPreferences.applicationTheme(context, true); GradientDrawable coloredCircle = new GradientDrawable(); coloredCircle.setColor(color); coloredCircle.setShape(GradientDrawable.OVAL); if (applicationTheme.equals("dark")) { if (position == 2) // dark gray color coloredCircle.setStroke(2, Color.parseColor("#6E6E6E")); } else { if (position == 0) // white color coloredCircle.setStroke(2, Color.parseColor("#AEAEAE")); } GradientDrawable darkerCircle = new GradientDrawable(); darkerCircle.setColor(shiftColor(color)); darkerCircle.setShape(GradientDrawable.OVAL); if (applicationTheme.equals("dark")) { if (position == 2) // dark gray color coloredCircle.setStroke(2, Color.parseColor("#6E6E6E")); } else { if (position == 0) // white color darkerCircle.setStroke(2, Color.parseColor("#AEAEAE")); } StateListDrawable stateListDrawable = new StateListDrawable(); stateListDrawable.addState(new int[]{-android.R.attr.state_pressed}, coloredCircle); stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, darkerCircle); return stateListDrawable; }
Example 18
Source File: MProgressBarDialog.java From MNProgressHUD with Apache License 2.0 | 4 votes |
private void configView() { try { //设置动画 if (mBuilder != null && mBuilder.animationID != 0 && mDialog.getWindow() != null) { mDialog.getWindow().setWindowAnimations(mBuilder.animationID); } } catch (Exception e) { } dialog_window_background.setBackgroundColor(mBuilder.backgroundWindowColor); tvShow.setTextColor(mBuilder.textColor); GradientDrawable myGrad = (GradientDrawable) dialog_view_bg.getBackground(); myGrad.setColor(mBuilder.backgroundViewColor); myGrad.setStroke(MSizeUtils.dp2px(mContext, mBuilder.strokeWidth), mBuilder.strokeColor); myGrad.setCornerRadius(MSizeUtils.dp2px(mContext, mBuilder.cornerRadius)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { dialog_view_bg.setBackground(myGrad); } else { dialog_view_bg.setBackgroundDrawable(myGrad); } //horizontalProgressBar 配置 //背景 GradientDrawable progressBarBackgroundDrawable = new GradientDrawable(); progressBarBackgroundDrawable.setColor(mBuilder.progressbarBackgroundColor); progressBarBackgroundDrawable.setCornerRadius(MSizeUtils.dp2px(mContext, mBuilder.progressCornerRadius)); //二级进度条 GradientDrawable secondProgressDrawable = new GradientDrawable(); secondProgressDrawable.setColor(mBuilder.progressbarBackgroundColor); secondProgressDrawable.setCornerRadius(MSizeUtils.dp2px(mContext, mBuilder.progressCornerRadius)); ClipDrawable hProgressBar02 = new ClipDrawable(secondProgressDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); //一级进度条 GradientDrawable progressDrawable = new GradientDrawable(); progressDrawable.setColor(mBuilder.progressColor); progressDrawable.setCornerRadius(MSizeUtils.dp2px(mContext, mBuilder.progressCornerRadius)); ClipDrawable hProgressBar03 = new ClipDrawable(progressDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); //组合 Drawable[] layers = {progressBarBackgroundDrawable, hProgressBar02, hProgressBar03}; LayerDrawable layerDrawable = new LayerDrawable(layers); layerDrawable.setId(0, android.R.id.background); layerDrawable.setId(1, android.R.id.secondaryProgress); layerDrawable.setId(2, android.R.id.progress); horizontalProgressBar.setProgressDrawable(layerDrawable); ViewGroup.LayoutParams layoutParams = horizontalProgressBar.getLayoutParams(); layoutParams.height = MSizeUtils.dp2px(mContext, mBuilder.horizontalProgressBarHeight); horizontalProgressBar.setLayoutParams(layoutParams); //circularProgressBar 配置 circularProgressBar.setBackgroundColor(mBuilder.progressbarBackgroundColor); circularProgressBar.setColor(mBuilder.progressColor); circularProgressBar.setProgressBarWidth(MSizeUtils.dp2px(mContext, mBuilder.circleProgressBarWidth)); circularProgressBar.setBackgroundProgressBarWidth(MSizeUtils.dp2px(mContext, mBuilder.circleProgressBarBackgroundWidth)); }
Example 19
Source File: ViewMaker.java From iGap-Android with GNU Affero General Public License v3.0 | 4 votes |
static View getViewVote() { LinearLayout lyt_vote = new LinearLayout(context); lyt_vote.setId(R.id.lyt_vote); lyt_vote.setGravity(BOTTOM); setLayoutDirection(lyt_vote, View.LAYOUT_DIRECTION_LTR); lyt_vote.setOrientation(VERTICAL); LinearLayout.LayoutParams layout_356 = new LinearLayout.LayoutParams(i_Dp(R.dimen.dp48), ViewGroup.LayoutParams.MATCH_PARENT); layout_356.gravity = BOTTOM; lyt_vote.setLayoutParams(layout_356); LinearLayout lyt_vote_sub = new LinearLayout(context); lyt_vote_sub.setOrientation(VERTICAL); lyt_vote_sub.setId(R.id.lyt_vote_sub); lyt_vote_sub.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.rectangel_white_round)); GradientDrawable circleDarkColor = (GradientDrawable) lyt_vote_sub.getBackground(); circleDarkColor.setColor(Color.parseColor(G.appBarColor)); LinearLayout.LayoutParams layout_35644 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layout_35644.leftMargin = i_Dp(R.dimen.dp2); lyt_vote_sub.setLayoutParams(layout_35644); LinearLayout lyt_vote_up = new LinearLayout(context); lyt_vote_up.setId(R.id.lyt_vote_up); lyt_vote_up.setGravity(CENTER); lyt_vote_up.setOrientation(VERTICAL); LinearLayout.LayoutParams layout_799 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); lyt_vote_up.setPadding(0, 0, 0, i_Dp(R.dimen.dp6)); layout_799.bottomMargin = i_Dp(dp4); lyt_vote_up.setLayoutParams(layout_799); TextView txt_vote_up = new TextView(context); txt_vote_up.setId(R.id.txt_vote_up); txt_vote_up.setText("0"); txt_vote_up.setTextAppearance(context, R.style.ChatMessages_Time); txt_vote_up.setSingleLine(true); setTypeFace(txt_vote_up); txt_vote_up.setTextColor(Color.parseColor(G.voteIconTheme)); LinearLayout.LayoutParams layout_713 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dpToPixel(16)); txt_vote_up.setLayoutParams(layout_713); lyt_vote_up.addView(txt_vote_up); MaterialDesignTextView img_vote_up = new MaterialDesignTextView(context); img_vote_up.setId(R.id.img_vote_up); img_vote_up.setText(context.getResources().getString(R.string.md_thumb_up)); img_vote_up.setTextColor(Color.parseColor(G.voteIconTheme)); setTextSize(img_vote_up, R.dimen.dp16); LinearLayout.LayoutParams layout_216 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); img_vote_up.setLayoutParams(layout_216); lyt_vote_up.addView(img_vote_up); lyt_vote_sub.addView(lyt_vote_up); LinearLayout lyt_vote_down = new LinearLayout(context); lyt_vote_down.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.rectangel_white_round)); GradientDrawable circleDarkColor_2 = (GradientDrawable) lyt_vote_down.getBackground(); circleDarkColor_2.setColor(Color.parseColor(G.appBarColor)); lyt_vote_down.setId(R.id.lyt_vote_down); lyt_vote_down.setPadding(0, i_Dp(R.dimen.dp6), 0, 0); lyt_vote_down.setGravity(CENTER); lyt_vote_down.setOrientation(VERTICAL); LinearLayout.LayoutParams layout_221 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); lyt_vote_down.setLayoutParams(layout_221); MaterialDesignTextView img_vote_down = new MaterialDesignTextView(context); img_vote_down.setId(R.id.img_vote_down); img_vote_down.setText(context.getResources().getString(R.string.md_thumb_down)); img_vote_down.setTextColor(Color.parseColor(G.voteIconTheme)); setTextSize(img_vote_down, R.dimen.dp16); LinearLayout.LayoutParams layout_877 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); img_vote_down.setLayoutParams(layout_877); lyt_vote_down.addView(img_vote_down); TextView txt_vote_down = new TextView(context); txt_vote_down.setId(R.id.txt_vote_down); txt_vote_down.setText("0"); txt_vote_down.setTextAppearance(context, R.style.ChatMessages_Time); setTypeFace(txt_vote_down); txt_vote_down.setSingleLine(true); txt_vote_down.setTextColor(Color.parseColor(G.voteIconTheme)); LinearLayout.LayoutParams layout_856 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dpToPixel(16)); txt_vote_down.setLayoutParams(layout_856); lyt_vote_down.addView(txt_vote_down); lyt_vote_sub.addView(lyt_vote_down); lyt_vote.addView(lyt_vote_sub); lyt_vote.addView(getForwardButton()); return lyt_vote; }
Example 20
Source File: ChartProgressBar.java From ChartProgressBar-Android with Apache License 2.0 | 4 votes |
public void enableBar(int index) { final int barsCount = ((LinearLayout) this.getChildAt(0)).getChildCount(); for (int i = 0; i < barsCount; i++) { FrameLayout rootFrame = (FrameLayout) ((LinearLayout) this.getChildAt(0)).getChildAt(i); int rootChildCount = rootFrame.getChildCount(); for (int j = 0; j < rootChildCount; j++) { if ((int) rootFrame.getTag() != index) continue; rootFrame.setEnabled(true); rootFrame.setClickable(true); View childView = rootFrame.getChildAt(j); if (childView instanceof LinearLayout) { //bar LinearLayout barContainerLinear = ((LinearLayout) childView); int barContainerCount = barContainerLinear.getChildCount(); for (int k = 0; k < barContainerCount; k++) { View view = barContainerLinear.getChildAt(k); if (view instanceof Bar) { Bar bar = (Bar) view; LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable(); layerDrawable.mutate(); ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1); GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable(); if (progressLayer != null) { if (mProgressColor > 0) progressLayer.setColor(ContextCompat.getColor(mContext, mProgressColor)); else progressLayer.setColor(ContextCompat.getColor(mContext, android.R.color.darker_gray)); } } else { TextView titleTxtView = (TextView) view; if (mProgressDisableColor > 0) titleTxtView.setTextColor(ContextCompat.getColor(mContext, mBarTitleColor)); else titleTxtView.setTextColor(ContextCompat.getColor(mContext, android.R.color.darker_gray)); } } } } } }