欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android EditText自定義樣式的方法

 更新時(shí)間:2016年02月20日 11:18:33   作者:一葉飄舟  
這篇文章主要介紹了Android EditText自定義樣式的方法,結(jié)合實(shí)例形式分析了EditText屬性的含義及樣式定義的技巧,需要的朋友可以參考下

本文實(shí)例講述了Android EditText自定義樣式的方法。分享給大家供大家參考,具體如下:

1.去掉邊框

EditText的background屬性設(shè)置為@null就搞定了:android:background="@null"
style屬性倒是可加可不加

附原文:

@SlumberMachine, that's a great observation! But, it seems that there is more to making a TextView editable than just setting android:editable="true". It has to do with the "input method" - what ever that is - and that is where the real difference between TextView and EditText lies. TextView was designed with an EditText in mind, that's for sure. One would have to look at the EditText source code and probably EditText style to see what's really going on there. Documentation is simply not enough.

I have asked the same question back at android-developers group, and got a satisfactory answer. This is what you have to do:

XML:

<EditText android:id="@+id/title" android:layout_width="fill_parent"
   style="?android:attr/textViewStyle"
   android:background="@null" android:textColor="@null"/>

Instead of style="?android:attr/textViewStyle" you can also write style="@android:style/Widget.TextView", don't ask me why and what it means.

2.Android EditText 改變邊框顏色

第一步:為了更好的比較,準(zhǔn)備兩個(gè)一模一樣的EditText(當(dāng)Activity啟動(dòng)時(shí),焦點(diǎn)會(huì)在第一個(gè)EditText上,如果你不希望這樣只需要寫一個(gè)高度和寬帶為0的EditText即可避免,這里就不這么做了),代碼如下:

<EditText
  android:layout_width="fill_parent"
    android:layout_height="36dip"
    android:background="@drawable/bg_edittext"
    android:padding="5dip"
  android:layout_margin="36dip"
  android:textColorHint="#AAAAAA"
  android:textSize="15dip"
  android:singleLine="true"
  android:hint="請(qǐng)輸入..."
/>

接下來建立三個(gè)xml文件,分別為輸入框未獲得焦點(diǎn)時(shí)的背景,輸入框獲得焦點(diǎn)時(shí)的背景,selector背景選擇器(這里能獲得輸入框什么時(shí)候獲得和失去焦點(diǎn)),代碼如下:

bg_edittext_normal.xml(未獲得焦點(diǎn)時(shí))

<?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>

bg_edittext_focused.xml(獲得焦點(diǎn)時(shí))

<?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>

bg_edittext.xml(selector選擇器,這方面資料網(wǎng)上很多)

<?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/contact_edit_edittext_normal" />
    <item android:state_focused="true" android:drawable="@drawable/contact_edit_edittext_focused" />
</selector>

這樣就OK了,效果圖如下:

第二個(gè)輸入框邊框變?yōu)樯钌?,是不是這樣更友好點(diǎn)。

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android通信方式總結(jié)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Flutter自定義Appbar搜索框效果

    Flutter自定義Appbar搜索框效果

    這篇文章主要為大家詳細(xì)介紹了Flutter自定義Appbar搜索框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • Android ListView詳解

    Android ListView詳解

    listview控件在項(xiàng)目開發(fā)過程中經(jīng)常會(huì)用到,本文給大家分享android listview相關(guān)知識(shí),感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12
  • Android?NotificationListenerService?通知服務(wù)原理解析

    Android?NotificationListenerService?通知服務(wù)原理解析

    這篇文章主要為大家介紹了Android?NotificationListenerService?通知服務(wù)原理解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • Android編程中的四大基本組件與生命周期詳解

    Android編程中的四大基本組件與生命周期詳解

    這篇文章主要介紹了Android編程中的四大基本組件與生命周期,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android四大組件及生命周期的相關(guān)概念與使用技巧,需要的朋友可以參考下
    2015-12-12
  • Android 文件存儲(chǔ)與SharedPreferences存儲(chǔ)方式詳解用法

    Android 文件存儲(chǔ)與SharedPreferences存儲(chǔ)方式詳解用法

    SharedPreferences是安卓平臺(tái)上一個(gè)輕量級(jí)的存儲(chǔ)類,用來保存應(yīng)用的一些常用配置,比如Activity狀態(tài),Activity暫停時(shí),將此activity的狀態(tài)保存到SharedPereferences中;當(dāng)Activity重載,系統(tǒng)回調(diào)方法onSaveInstanceState時(shí),再從SharedPreferences中將值取出
    2021-10-10
  • Android 自定義AlertDialog對(duì)話框樣式

    Android 自定義AlertDialog對(duì)話框樣式

    實(shí)際的項(xiàng)目開發(fā)當(dāng)中,經(jīng)常需要根據(jù)實(shí)際的需求來自定義AlertDialog。最近在開發(fā)一個(gè)WIFI連接的功能,點(diǎn)擊WIFI需要彈出自定義密碼輸入框,具體代碼大家參考下本文
    2017-09-09
  • Kotlin StateFlow單數(shù)據(jù)更新熱流設(shè)計(jì)與使用介紹

    Kotlin StateFlow單數(shù)據(jù)更新熱流設(shè)計(jì)與使用介紹

    StateFlow當(dāng)值發(fā)生變化,就會(huì)將值發(fā)送出去,下流就可以接收到新值。在某些場(chǎng)景下,StateFlow比LiveData更適用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2022-09-09
  • Android 多圖上傳后將圖片進(jìn)行九宮格展示的實(shí)例代碼

    Android 多圖上傳后將圖片進(jìn)行九宮格展示的實(shí)例代碼

    這篇文章主要介紹了Android 多圖上傳后將圖片進(jìn)行九宮格展示,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • Android動(dòng)畫之小球擬合動(dòng)畫實(shí)例

    Android動(dòng)畫之小球擬合動(dòng)畫實(shí)例

    這篇文章主要介紹了Android動(dòng)畫之小球擬合動(dòng)畫實(shí)例的相關(guān)資料,需要的朋友可以參考下
    2017-07-07
  • 詳解ASP.NET Core MVC四種枚舉綁定方式

    詳解ASP.NET Core MVC四種枚舉綁定方式

    這篇文章主要介紹了詳解ASP.NET Core MVC四種枚舉綁定方式, 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-04-04

最新評(píng)論