給Android4.X版本的EditText恢複邊框

來源:互聯網
上載者:User

標籤:normal   android   底線   4.0   edittext   

Android4.0以後的版本的EditText的新特徵是以單底線的形式出現,但是很多時候我們需要加上邊框看起來比較美觀.下面請看具體操作:

分為兩部分:未輸入文本時的狀態(normal)和點擊輸入文本的狀態(focused).

下面是EditText的控制項:

<EditText          android:layout_width="fill_parent"          android:layout_height="36dip"          android:background="@drawable/edittext"          android:padding="5dip"          android:layout_margin="36dip"          android:textColorHint="#AAAAAA"          android:textSize="15dip"          android:hint="@string/asdasd_"        android:singleLine="true" />

其中android:background="@drawable/edittext"  是另外定義的edittext.xml選取器(存放在drawable任意檔案夾下)下面定義edittext.xml

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

接著就是定義edittext_normal.xml和edittext_focused.xml檔案,具體如下:

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="3dip" />          <stroke android:width="1dip" android:color="#BDC7D8" />      </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="3dip" />      <stroke android:width="1dip" android:color="#728ea3" />  </shape>

效果:650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/51/15/wKioL1Ri75KDJ9IqAAEDf25KCAE481.jpg" title="2014-11-12 13:23:51 的螢幕.png" alt="wKioL1Ri75KDJ9IqAAEDf25KCAE481.jpg" />

本文出自 “可愛的xiaopp” 部落格,請務必保留此出處http://smartxiaopp.blog.51cto.com/9349053/1575658

給Android4.X版本的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.