在Android中自訂IOS風格的按鈕

來源:互聯網
上載者:User

IOS風格的UI比較流行,很多Android的UI設計者也願意將Android的UI設計成類似IOS系統的UI風格。下面是一個例子,說明如何使用Shape來定義一個IOS風格的按鈕。

 

定義一個ios_button_grouped.xml。

<?xmlversion="1.0"encoding="UTF-8"?>

<selector

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

    <item

       android:state_pressed="true"

       android:drawable="@drawable/ios_button_grouped_pressed"/>

    <item

       android:state_focused="true"

       android:state_window_focused="true"

       android:drawable="@drawable/ios_button_grouped_pressed"/>

    <item

       android:drawable="@drawable/ios_button_grouped_normal"/>

</selector>

 

 

定義ios_button_grouped_normal.xml

<?xmlversion="1.0"encoding="utf-8"?>

<shape

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

    android:shape="rectangle">

    <solid

       android:color="#eee"/>

    <stroke

       android:width="1dp"

       android:color="@android:color/black"/>

    <corners

       android:radius="5dp"/>

</shape>

 

定義ios_button_grouped_pressed.xml

<?xmlversion="1.0"encoding="utf-8"?>

<shape

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

    android:shape="rectangle">

    <solid

       android:color="#0be"/>

    <stroke

       android:width="1dp"

       android:color="@android:color/black"/>

    <corners

       android:radius="5dp"/>

</shape>

 

這裡主要是定義Shape中的rectangle的顏色。還有一些顏色屬性可以設定,比如startColor,endColor,angle等等,可以定義出漂亮的UI效果。建議參考API文檔。

 

效果:

  


 

使用方法:

當做圖片作為背景使用即可。

android:background="@drawable/ios_button_grouped"

 

---------------------------------------------------------------------------

GL(arui319)

http://blog.csdn.net/arui319

 

摘自  迷途ф書童
  

聯繫我們

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