Android--shape-指定图形的corners、gradient、padding、size、solid、stroke属性
16lz
2021-01-23
android工程创建一个shape类型的xml资源,自定义一个漂亮的控件:
1.创建shape类型xml资源文件
res目录下的 新建一个根标签root element为shape的xml文件:
2.xml中详细描述
文件名:btn_shape_demo.xml:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="8dp" android:topLeftRadius="5dp" android:topRightRadius="15dp" android:bottomLeftRadius="20dp" android:bottomRightRadius="25dp" /> <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF" android:angle="45" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> <size android:width="180dp" android:height="100dp" /> <solid android:color="#ff65b3ff" /> <stroke android:width="6dp" android:color="#dcdcdc" />shape>
3.引用 drawable/btn_shape_demo
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" tools:context=".MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:background="@drawable/btn_shape_demo" android:text="ShapeDemo" />RelativeLayout>
4.效果图
更多相关文章
- Android 中颜色对应的代码集合
- Android沉浸式(设置状态栏颜色)
- 设置android的布局文件的背景颜色为黑色
- Android 动态设置颜色
- Android Textview实现颜色渐变滚动效果
- Android TextView内容设置超链接、颜色、字体
- Android原生AlertDialog修改标题,内容,按钮颜色,字体大小等
- Android的supportV7中默认按钮的颜色设置
- 72、android状态栏一体化,状态栏改变颜色