Android美化EditText

來源:互聯網
上載者:User

標籤:android   使用者體驗   edittext   

目前各種app都講究使用者體驗,這裡介紹下對EditText控制項的樣式美化。


先上:

          

註:第一個控制項沒有沒有設定 background 的任何屬性,第二個控制項設定了 android:background="@drawable/bg_edittext_selector"

若希望取消 EditText 背景,直接設定 android:background="@null" 便可。


此處通過兩個xml檔案來設定未獲得焦點和已經獲得焦點的樣式,通過shape實現。

edittext_focused.xml

<?xml version="1.0" encoding="UTF-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">    <solid android:color="#FFFFFF" />        <corners android:radius="1dip"/>        <stroke        android:width="1dip"        android:color="#728ea3" /></shape>


edittext_normal.xml

<?xml version="1.0" encoding="UTF-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">    <solid android:color="#FFFFFF" />    <corners android:radius="1dip"/>    <stroke        android:width="1dip"        android:color="#BDC7D8" /></shape>


註:此處可以通過設定 corners   (角) 來設定邊框的弧度。想瞭解shape更多屬性可以自行查閱。


bg_edittext_selector.xml

<?xml version="1.0" encoding="UTF-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/edittext_normal" android:state_window_focused="false"/>    <item android:drawable="@drawable/edittext_focused" android:state_focused="true"/></selector>


activity_main.xml

<RelativeLayout 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="com.example.aa.MainActivity" >    <EditText        android:id="@+id/normal"        android:layout_width="fill_parent"        android:layout_height="36dip"        android:layout_margin="36dip"        android:hint="請輸入使用者名稱"        android:padding="5dip"        android:singleLine="true"        android:textColorHint="#AAAAAA"        android:textSize="15dip" />    <EditText        android:layout_below="@+id/normal"        android:layout_width="fill_parent"        android:layout_height="36dip"        android:layout_margin="36dip"        android:background="@drawable/bg_edittext_selector"        android:hint="請輸入使用者名稱"        android:padding="5dip"        android:singleLine="true"        android:textColorHint="#AAAAAA"        android:textSize="15dip" /></RelativeLayout>


Android美化EditText

聯繫我們

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