定义可绘制形状与JAVA code形状、定义、code、JAVA

2023-09-07 09:26:30 作者:野鸡贩大叔!!

喜 我可以定义这个形状,而不使用XML code

Hi Can I define this shape without using xml code

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#34342C" android:endColor="#848486"
    android:angle="90" />
<padding android:left="7dp" android:top="5dp" android:right="7dp"
    android:bottom="5dp" />
<stroke android:width="1dp" android:color="#FFFFFF" />
</shape>

感谢您的帮助

Thanks for your help

推荐答案

使用 ShapeDrawable 绘制您的矩形与 您需要 使用涂料与适当的颜色和的描边宽度 使用线性渐变并添加这对漆作为渲染 use a ShapeDrawable to draw your rectangle with the padding you require using a Paint with the appropriate color and stroke width using a Linear gradient and adding this to the Paint as a shader