草庐IT

GradientDrawable

全部标签

android - 用于旧 API 级别的 GradientDrawable setColors

是否可以在比API16(JellyBean)更低的API级别上设置形状中渐变的颜色数组?我目前正在使用:GradientDrawablegd=(GradientDrawable)this.getBackground();int[]colors={0xFFFF0000,0xFFCC0099};gd.setColors(colors);效果很好,但我希望支持API级别8(Froyo)或10(Gingerbreadv2)。 最佳答案 我认为没有简单的方法可以做到这一点,所以我建议这样做:创建一个新的GradientDrawable基于旧参

android - java.lang.ClassCastException : android. graphics.drawable.LayerDrawable 无法转换为 android.graphics.drawable.GradientDrawable

在我的应用程序中,我正在尝试更改每个listView项目的背景颜色。为此,我使用图层列表中的形状。这是我的代码drop_shadow.xml主.xml当我调用这个方法时我有ClassCastExceptionprivatevoidsetRoundedBackground(Viewview,intcolor){GradientDrawablegradientDrawable;gradientDrawable=(GradientDrawable)view.getBackground().mutate();gradientDrawable.setColor(getResources().ge

Android以编程方式更改颜色描边(边框)

我尝试通过“GradientDrawable”改变颜色“描边”,但不起作用。另外,我不知道如何获取idstroke,并且只更改笔划(我看到google,所有示例都失败了)我的XML项目GradientDrawablegd=(GradientDrawable)circleProgress.getBackground();gd=(GradientDrawable)circleProgress.getBackground();gd.setColor(Color.RED);android.graphics.drawable.LayerDrawablecannotbecasttoandroid.

java - 哪些颜色值可以用于 GradientDrawable

在我的应用程序中,我试图从代码中绘制一个gradientBackground。我的目标是让这个背景动态。现在我的问题是下面这个函数是我正在谈论的函数,并且有一个参数int[]colorsGradientDrawable(GradientDrawable.Orientationorientation,int[]colors);我可以在int[]颜色中输入哪些值?我知道以下值有效。0xAARRGGBB但我的问题是,我在我的程序中重新计算哈希值,但它们以字符串结尾,但它必须以整数结尾。并且无法将哈希值转换为:String0x34F323到Int0x34F323。当我重新计算哈希值并得到:字符

android - 以编程方式更改图层列表 Drawable 项的底部属性

我正在创建一个LayerDrawable来创建底部笔划,但我不知道如何给出图层的底部边距(Drawablw)。..我想像上面那样以编程方式设置底部边距。到目前为止我已经这样做了:Drawable[]list=newDrawable[2];GradientDrawablestrokeDrawable=newGradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,newint[]{strokeColor[0],strokeColor[0]});GradientDrawablebackgroundDrawable=newGradien

android - 以编程方式更改小部件的渐变背景

我想要完成的事情:int[]colors=newint[]{colorDark,colorLight}GradientDrawablegd=newGradientDrawable(TOP_BOTTOM,colors);remoteView.setBackgroundDrawable(gd);//methoddoesnotexist显然这是不可能的。我怎样才能做到这一点?(如果可能的话)我不想在xml文件中为不同的颜色创建多个形状,因为这会限制选项。我已尝试将我的可绘制对象转换为位图并调用setImageViewBitmap。我用thiscode转换了并使用thiscode获取宽度/高度

android - 如何在java代码中为按钮设置圆角半径?

我想在没有xml的情况下设置圆角。我怎样才能用java代码做到这一点?Buttonb=newButton(this);b.set????(??);我尝试编写b.setCornerRadius(3.0f),但它没有为按钮对象定义。谢谢。 最佳答案 使用GradientDrawableGradientDrawablegdDefault=newGradientDrawable();gdDefault.setColor(bgColor);gdDefault.setCornerRadius(cornerRadius);gdDefault.se

android - GradientDrawable 类的 innerRadiusRatio 和 thicknessRatio 之间存在什么样的联系?

假设我们有一个内径R2和外径R1的环。根据文档:环的内半径表示为环宽度的比率。例如,如果innerRadiusRatio=9,则内半径等于环的宽度除以9据我了解,这意味着innerRadiusRatio=2*R1/R2。关于thicknessRatio有:环的厚度表示为环宽度的比率。例如,如果thicknessRatio=3,则厚度等于环的宽度除以3。所以thicknessRatio=2*R1/(R1-R2)。从这两个等式我们可以得到这个:thicknessRatio*(1-2/innerRadiusRatio)=2这意味着thicknessRatio和innerRadiusRatio

android - 以编程方式设置渐变背景

我有一张图像,我在上面放置了彩色叠加层,就像这样(颜色取自here):布局/list_item_view.xmldrawable/gradient_blue.xml这总是放置一个蓝色覆盖层(CornflowerBlue),并且按预期工作。现在我正在尝试以编程方式执行此操作并遵循一些stackoverflow答案(例如this),但仍然无法使其工作。这是我的代码:privatevoidsetColor(intcolor){ViewgradientCover=view.findViewById(R.id.image_cover_gradient);//thisFAILSbecauseit'

android - 以编程方式绘制 LayerDrawable

因为我的应用程序的颜色主题是动态的,所以我只能使用颜色和形状绘制来创建背景绘制,我想构建一个可绘制的带有颜色和形状的edittext背景,如下所示。但我想以编程方式执行此操作如何以编程方式构建相同的可绘制对象?这是我试过的....GradientDrawableborder=newGradientDrawable();border.setShape(GradientDrawable.RECTANGLE);border.setColor(Color.WHITE);GradientDrawablebackground=newGradientDrawable();background.set