安卓--shape簡單使用,安卓--shape
shape
先看下,系統內建的EditText和Button的外形
下面看加了shape後的效果
簡單點講,shape可以為組件加上背景邊框,圓角之類的可以配合selector使用
shapeXXX.xml定義在drawable目錄下
EditText使用的
<?xml version="1.0" encoding="utf-8"?><!--rectangle 矩形oval 橢圓line 一條線ring 環形--><shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> <!--4個角的圓角--> <corners android:radius="5dp"/> <!--內邊距--> <padding android:bottom="6dp" android:left="5dp" android:right="5dp" android:top="6dp"/> <!--填充顏色 按需求要不要加 --> <solid android:color="#FFFAE3"/> <!--邊框顏色 需要 就加邊框, --> <stroke android:color="#87CEFA" android:width="1dp"/> </shape>
Button使用的定義的都 一樣
<?xml version="1.0" encoding="utf-8"?><!--rectangle 矩形oval 橢圓line 一條線ring 環形--><shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> <!--4個角的圓角--> <corners android:radius="8dp"/> <!--內邊距--> <padding android:bottom="5dp" android:left="3dp" android:right="3dp" android:top="5dp"/> <!--填充顏色--> <solid android:color="#09A3DC"/> <!--邊框顏色--> <stroke android:color="#88000000" android:width="1dp"/> </shape>
布局中組使用在background屬性中使用
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:layout_margin="10dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/shap_et" android:hint="請輸入使用者名稱" /> <Button android:layout_margin="10dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#ffffff" android:background="@drawable/shap_btn" android:text="確定"/></LinearLayout>