
我想构建一个可用颜色和形状绘制的edittext背景,如下所示.
但我想以编程方式执行此 *** 作
如何以编程方式构建同样的drawable?
<item> <shape> <solID androID:color="@androID:color/yellow" /> </shape></item><!-- main color --><item androID:bottom="1dp" androID:left="1dp" androID:right="1dp"> <shape> <solID androID:color="@androID:color/white" /> </shape></item><!-- draw another block to cut-off the left and right bars --><item androID:bottom="10dp"> <shape> <solID androID:color="@androID:color/white" /> </shape></item>
这就是我试过的……
GradIEntDrawable border = new GradIEntDrawable(); border.setShape(GradIEntDrawable.RECTANGLE); border.setcolor(color.WHITE); GradIEntDrawable background = new GradIEntDrawable(); background.setShape(GradIEntDrawable.RECTANGLE); background.setcolor(color.YELLOW); GradIEntDrawable clip = new GradIEntDrawable(); clip.setShape(GradIEntDrawable.RECTANGLE); border.setcolor(color.WHITE); Drawable[] layers = {background,border,clip}; LayerDrawable layerDrawable = new LayerDrawable(layers); layerDrawable.setLayerInset(0,0); layerDrawable.setLayerInset(1,1,1); layerDrawable.setLayerInset(2,10); 但结果是不同的….请帮助……!
解决方法 我终于搞定了.而不是使用GradIEntDrawable我使用了ShapeDrawable.通过将此LayerDrawable设置为EditText背景,您可以重新生成默认的EditText
自定义颜色的样式.
ShapeDrawable border = new ShapeDrawable();border.getPaint().setcolor(color.WHITE);ShapeDrawable background = new ShapeDrawable();background.getPaint().setcolor(color.BLACK);ShapeDrawable clip = new ShapeDrawable();clip.getPaint().setcolor(color.WHITE);Drawable[] layers = {background,clip};LayerDrawable layerDrawable = new LayerDrawable(layers);layerDrawable.setLayerInset(0,0);layerDrawable.setLayerInset(1,1);layerDrawable.setLayerInset(2,10); 总结 以上是内存溢出为你收集整理的android – LayerDrawable以编程方式全部内容,希望文章能够帮你解决android – LayerDrawable以编程方式所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)