Android 自訂android控制項EditText邊框背景

來源:互聯網
上載者:User

標籤:

在我們進行Android應用介面設計和時候,為了介面風格的統一,我們需要對一些控制項進行自訂。比如我們的應用採用的藍色風格,但是 android的EditText控制獲得焦點後顯示的卻是黃色的邊框背景。那麼如何讓EditText在獲得焦點的時候顯示的是我們自訂的藍色的背景 呢?

首先準備兩張圖片,一張是EditText獲得焦點後的邊框背景,一張是沒有獲得焦點時的背景,注意製作成9.png樣式的圖片,然後在drawable裡添加一個selector_edittext_bg.xml檔案,內容如下:

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

然後在values檔案夾下建立一個style.xml檔案,內容如下:

<?xml version="1.0" encoding="utf-8"?><resources>    <style name="my_edittext_style" parent="@android:style/Widget.EditText">        <item name="android:background">@drawable/selector_edittext_bg</item>    </style></resources>

最後在EditTex上使用我們建立的樣式就可以了:

<EditText            android:id="@+id/v_value"            style="@style/my_edittext_style"            android:layout_width="0.0dip"            android:layout_height="wrap_content"            android:layout_weight="1"            android:hint="@string/edit_key"            android:imeOptions="actionDone"            android:inputType="" />

 

Android 自訂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.