这是一种方法(感谢Android文档!):
将以下内容添加到文件(例如customshape.xml)中,然后将其放入(res / drawable / customshape.xml)
android:shape="rectangle">
android:startColor="#SomeGradientBeginColor"
android:endColor="#SomeGradientEndColor"
android:angle="270"/>
android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
完成创建此文件后,只需使用以下方法之一设置背景:
通过代码: listView.setBackgroundResource(R.drawable.customshape);
通过XML,只需将以下属性添加到容器中(例如:LinearLayout或任何字段):
android:background="@drawable/customshape"
希望有人发现它有用......