草庐IT

GradientDrawable

全部标签

android - GradientDrawable绘制不同颜色的setColor方法

我在layer-list中有一个shape,我的目标是在运行时以编程方式更改shape的颜色。我有十六进制代码的字符串,我使用Color.parseColor()解析它,然后传递给setColor方法。每当我运行该应用程序时,它都会显示与我预期不同的颜色。这是我的XML文件代码:这是我在CustomAdapter中的代码:convertView=mInflater.inflate(R.layout.student_info_selection_fragment_icon,null);holder=newViewHolder();holder.collegeBG=(LayerDrawab

java - 如何设置android :angle property of GradientDrawable programmatically?

这是我的颜色列表:staticArrayListcolors;static{colors=newArrayList();colors.add(Color.parseColor("#43CFCF"));colors.add(Color.parseColor("#1C6E9B"));colors.add(Color.parseColor("#AC88C0"));colors.add(Color.parseColor("#EE5640"));colors.add(Color.parseColor("#EFBF4D"));}这是我的可绘制数组:staticDrawable[]drawables

android - 如何解决 GradientDrawable cannot be cast to ColorDrawable 问题?

我有一个代码fragment可以在下面向您展示,我正在尝试更改View的(v)背景。我将从TextView(拖动)中获取颜色代码,并使用此代码更改View(v)的背景。但是我得到一个错误,如上所述。我该如何解决?问题出在哪里?谢谢。ColorDrawablecd=(ColorDrawable)dragged.getBackground();intcolorCode=cd.getColor();v.setBackgroundColor(colorCode); 最佳答案 如果您只想将一个View的背景分配给另一个View而不仅仅是颜色,

android - GradientDrawable 以编程方式改变角度

我有以下GradientDrawable的xml。如何以编程方式更改角度? 最佳答案 GradientDrawable有一个方法叫做:.setOrientation(GradientDrawable.Orientationorientation),你可以用这个改变渐变的方向。您需要将XML扩展为GradientDrawable。 关于android-GradientDrawable以编程方式改变角度,我们在StackOverflow上找到一个类似的问题: ht

android - 使用设置了三种以上颜色的 gradientDrawable

根据我的阅读,您可以使用gradientDrawable并为其设置三种颜色,例如:但是如果我想要三种以上的颜色,不仅如此,我还希望能够设置每种颜色的放置位置(重量/百分比)?是否可以使用API或者我应该制作自己的自定义可绘制对象?如果我需要制作自己的自定义drawable,我应该怎么做? 最佳答案 将此代码放入您的onCreate()方法中:ShapeDrawable.ShaderFactoryshaderFactory=newShapeDrawable.ShaderFactory(){@OverridepublicShaderre

android - 代码中的 GradientDrawable

我可以使用下面的XML就好了渐变效果很好我正在尝试仅使用代码(无XML)来做同样的事情intcolors[]={0xff255779,0xff3e7492,0xffa6c0cd};GradientDrawableg=newGradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,colors);setBackgroundDrawable(g);渐变确实出现了,但它与XML中的不一样,我的意思是颜色相同但渐变不一样,我认为这与xml中的开始、中间、结束颜色有关还有如何添加笔画任何帮助将不胜感激 最佳答案