最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android EditText自定義樣式的方法

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

本文實例講述了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 改變邊框顏色

第一步:為了更好的比較,準備兩個一模一樣的EditText(當Activity啟動時,焦點會在第一個EditText上,如果你不希望這樣只需要寫一個高度和寬帶為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="請輸入..."
/>

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

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

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

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了,效果圖如下:

第二個輸入框邊框變?yōu)樯钌遣皇沁@樣更友好點。

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

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

相關(guān)文章

  • Android控件系列之RadioButton與RadioGroup使用方法

    Android控件系列之RadioButton與RadioGroup使用方法

    本文介紹了Android中如何使用RadioGroup和RadioButton,對比了RadioButton和CheckBox的區(qū)別,并實現(xiàn)了自定義的RadioGroup中被選中RadioButton的變更監(jiān)聽事件
    2012-11-11
  • JetPack Compose底部導航欄的實現(xiàn)方法詳解

    JetPack Compose底部導航欄的實現(xiàn)方法詳解

    開發(fā)一個新項目,底部導航欄一般是首頁的標配,在以前的xml布局中,我們可以很輕松的是用谷歌提供的BottomNavigationView或者自定義來實現(xiàn)底部導航的功能,在Compose中也有也提供了一個類似的控件androidx.compose.material.BottomNavigation
    2022-09-09
  • 使用科大訊飛語音SDK實現(xiàn)文字在線合成語音

    使用科大訊飛語音SDK實現(xiàn)文字在線合成語音

    這篇文章主要介紹了使用科大訊飛語音SDK實現(xiàn)文字在線合成語音 的相關(guān)資料,需要的朋友可以參考下
    2015-12-12
  • Android Camera2采集攝像頭原始數(shù)據(jù)

    Android Camera2采集攝像頭原始數(shù)據(jù)

    這篇文章主要介紹了Android Camera2采集攝像頭原始數(shù)據(jù)并進行手工預(yù)覽的功能實現(xiàn)原理以及代碼分析,需要的朋友學習下吧。
    2018-02-02
  • Android 獲取簽名公鑰和公鑰私鑰加解密的方法(推薦)

    Android 獲取簽名公鑰和公鑰私鑰加解密的方法(推薦)

    下面小編就為大家?guī)硪黄狝ndroid 獲取簽名公鑰和公鑰私鑰加解密的方法(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-12-12
  • Android Studio中快捷鍵實現(xiàn)try catch等功能包含代碼塊的實現(xiàn)方法

    Android Studio中快捷鍵實現(xiàn)try catch等功能包含代碼塊的實現(xiàn)方法

    這篇文章主要介紹了 Android Studio中快捷鍵實現(xiàn)try catch等功能包含代碼塊的實現(xiàn)方法的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-09-09
  • Listview加載的性能優(yōu)化是如何實現(xiàn)的

    Listview加載的性能優(yōu)化是如何實現(xiàn)的

    在android開發(fā)中Listview是一個很重要的組件,它以列表的形式根據(jù)數(shù)據(jù)的長自適應(yīng)展示具體內(nèi)容,用戶可以自由的定義listview每一列的布局,接下來通過本文給大家介紹Listview加載的性能優(yōu)化是如何實現(xiàn)的,對listview性能優(yōu)化相關(guān)知識感興趣的朋友一起學習吧
    2016-01-01
  • Android 物理按鍵整理及實例代碼

    Android 物理按鍵整理及實例代碼

    這篇文章主要介紹了Android 物理按鍵整理及實例代碼的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • Android中Item實現(xiàn)點擊水波紋效果

    Android中Item實現(xiàn)點擊水波紋效果

    這篇文章主要給大家介紹了關(guān)于Android中Item實現(xiàn)點擊水波紋效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2018-11-11
  • Android繪圖技巧使用詳解

    Android繪圖技巧使用詳解

    這篇文章主要為大家詳細介紹了Android繪圖技巧的使用,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-09-09

最新評論

桑植县| 永德县| 凤城市| 大理市| 额尔古纳市| 呼伦贝尔市| 宜章县| 象州县| 云霄县| 达孜县| 巫山县| 济南市| 沽源县| 金山区| 桂阳县| 泰和县| 融水| 杭州市| 临洮县| 平顺县| 纳雍县| 丹巴县| 闸北区| 中宁县| 兴文县| 宿州市| 赤峰市| 林周县| 曲阳县| 南乐县| 正定县| 易门县| 丰宁| 吴川市| 汉沽区| 泰州市| 郑州市| 奇台县| 沂南县| 德保县| 辛集市|