Android学习第五天--自定义图形
在drawable中创建一个xml文件
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="10dp"/> <padding android:left="20dp" /> <solid android:color="#ff0000"/> <stroke android:color="#00ff00" android:width="5dp"/> <gradient android:startColor="#ffffff" android:endColor="#000000" android:angle="270" /> </shape>
其中<corners>是设置园的半径,效果是让输入框等图形的边框有圆角
<padding>是让图形距离左边20dp
<solid >设置背景颜色
<stroke>设置变宽颜色,边框宽度
<gradient>设置角度,起始颜色,结束颜色
主xml中
<LinearLayout 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" tools:context=".MainActivity" android:orientation="vertical" android:background="@drawable/ic_launcher"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/edittext_shape" /> </LinearLayout>
在主xml目录中创建xml文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > </LinearLayout>
这样就可以利用自定义的图形进行背景替换等操作。