由于我的应用程序颜色主题是动态的,因此我只能使用颜色和形状可绘制对象来创建背景可绘制对象。 我想使用颜色和形状构建下面显示的edittext背景可绘制对象。 但我想以编程方式实现这一点。
如何以编程方式构建相同的可绘制对象?
<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, 0, 0, 0);
layerDrawable.setLayerInset(1, 1, 0, 1, 1);
layerDrawable.setLayerInset(2, 0, 0, 0, 10);
但结果不同......请帮忙....!