安卓--shape簡單使用,安卓--shape

來源:互聯網
上載者:User

安卓--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>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.