Android 扁平化button

來源:互聯網
上載者:User

標籤:div   ext   button背景   orm   ==   pre   water   drawable   cto   

View

建立 colors.xml 檔案定義兩個顏色

1. <resources>

2.     <color name="blue_pressed">@android:color/holo_blue_dark</color>

3.     <color name="blue_normal">@android:color/holo_blue_light</color>

4. </resources>

我們這裡使用android的 HOLO 色調:

1. <!-- A dark Holo shade of blue -->

2. <color name="holo_blue_dark">#ff0099cc</color>

3. <!-- A light Holo shade of blue -->

4. <color name="holo_blue_light">#ff33b5e5</color>

建立 dimen.xml 檔案,定義圓角值和陰影高度。見

1. <resources>

2.     <dimen name="corner_radius">4dp</dimen>

3.     <dimen name="layer_padding">3dp<<dimen>

4. </resources>

 

 

我們用shape來定義button背景 建立rect_pressed.xml 的 drawable 檔案

1. <shape xmlns:android="http://schemas.android.com/apk/res/android"

2.     android:shape="rectangle">

3.   <corners android:radius="@dimen/corner_radius" />

4.   <solid android:color="@color/blue_pressed" />

5. </shape>

 

建立rect_normal.xml file 的drawable 檔案。

1. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">

2.   <item android:drawable="@drawable/rect_pressed" />

3.  

4.   <item android:bottom="@dimen/layer_padding">

5.       <shape android:shape="rectangle">

6.           <corners android:radius="@dimen/corner_radius" />

7.           <solid android:color="@color/blue_normal" />

8.       </shape>

9.   </item>

10. </layer-list>

 

為button定義 selector . 建立flat_selector.xml 檔案。

1. <selector xmlns:android="http://schemas.android.com/apk/res/android">

2.   <item android:state_pressed="true" android:drawable="@drawable/rect_pressed"/>

3.   <item android:drawable="@drawable/rect_normal"/>

4. </selector>

定義 button 設定 background 為 flat_selector.

1. <Button

2.       android:layout_width="fill_parent"

3.       android:layout_height="wrap_content"

4.       android:background="@drawable/flat_selector"

5.       android:textColor="@android:color/white"

6.       android:text="Say Hello" />

Android 扁平化button

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.