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

Android高級xml布局之輸入框EditText設(shè)計

 更新時間:2021年06月23日 15:19:46   作者:AndroidMsky  
這篇文章主要為大家詳細(xì)介紹了Android高級xml布局之輸入框EditText設(shè)計,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

今天給大家介紹一下如何實現(xiàn)一款簡約時尚的安卓登陸界面。大家先看一下效果圖

當(dāng)用戶輸入時動態(tài)出現(xiàn)刪除按鈕

現(xiàn)在先羅列一下技術(shù)點:

1.如何使用圓角輸入框和按鈕背景
2.如何實現(xiàn)“手機號”、“密碼”后面的豎線
3.如何嵌套輸入框的布局
4.如何監(jiān)聽輸入框的輸入事件及刪除按鈕的動態(tài)顯示隱藏

1.如何使用圓角輸入框和按鈕背景

安卓為開發(fā)者準(zhǔn)備了shape這個xml標(biāo)簽,用于自定義一些形狀。
那么我就來定義一個白色的輸入框背景。代碼如下:

<!-- 形狀 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle" >

 <solid android:color="#ffffff" />
 <!-- 邊框 -->
 <stroke
 android:width="1dip"
 android:color="#ffffff" />
 <!-- 內(nèi)填充顏色 -->
 <padding
 android:bottom="10dp"
 android:left="10dp"
 android:right="10dp"
 android:top="10dp" />
 <!-- 圓角 -->
 <corners android:radius="6dp" />

</shape>

將其設(shè)置成任何View的background就可以了

android:background="@drawable/shape_wihte_frame"

2.如何實現(xiàn)“手機號”、“密碼”后面的豎線

這個其實很簡單,只需書寫一個豎線即可,寬度為1dp或者1px(或你認(rèn)為更合適的數(shù)值)。 

 <View
 android:id="@+id/view1"
 android:layout_width="1dip"
 android:layout_height="fill_parent"
 android:layout_centerVertical="true"
 android:layout_gravity="center_horizontal"
 android:layout_marginLeft="2dp"
 android:layout_marginRight="2dp"
 android:layout_toRightOf="@+id/textView1"
 android:background="#EEEFFF" />

3.如何嵌套輸入框的布局

安卓給我們提供了多種布局,但是你用任何一種都沒辦法把界面設(shè)計好。必須嵌套,很多新手不敢去嵌套,大家一定要大膽的去嵌套去使用各種布局,一定會組合出炫酷的效果的。這里布局很簡單僅僅是一層嵌套(整個頁面布局嵌套輸入框的布局)。

 <RelativeLayout
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:background="@drawable/shape_wihte_frame" >

 <TextView
 android:id="@+id/textView1"
 android:layout_width="40dp"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_centerVertical="true"
 android:lines="1"
 android:padding="1dp"
 android:text="手機號"
 android:textSize="11sp" />

 <View
 android:id="@+id/view1"
 android:layout_width="1dip"
 android:layout_height="fill_parent"
 android:layout_centerVertical="true"
 android:layout_gravity="center_horizontal"
 android:layout_marginLeft="2dp"
 android:layout_marginRight="2dp"
 android:layout_toRightOf="@+id/textView1"
 android:background="#EEEFFF" />

 <EditText
 android:id="@+id/phonenumber"
 android:layout_width="wrap_content"
 android:layout_height="40dp"
 android:layout_centerVertical="true"
 android:layout_marginLeft="2dp"
 android:layout_toRightOf="@+id/view1"
 android:background="@drawable/transparent"
 android:ems="19"
 android:hint="請輸入手機號"
 android:inputType="phone"
 android:padding="1dp"
 android:textSize="12sp" >

 <requestFocus />
 </EditText>

 <ImageView
 android:id="@+id/del_phonenumber"
 android:layout_width="20dp"
 android:layout_height="20dp"
 android:layout_alignParentRight="true"
 android:layout_centerVertical="true"
 android:layout_marginRight="3dp"
 android:src="@drawable/text_del"
 android:visibility="invisible" />
 </RelativeLayout>

4.如何監(jiān)聽輸入框的輸入事件及刪除按鈕的動態(tài)顯示隱藏

思想很簡單,就是監(jiān)聽EditText的輸入事件,之后如果輸入長度大于0就顯示后面的刪除按鈕,如果=0就隱藏刪除按鍵,點擊刪除按鈕就清空輸入框。在這里我寫出了一個工具類方便大家調(diào)用。高內(nèi)聚低耦合是我們共同的追求。

public class EditTextClearTools {
 public static void addclerListener(final EditText e1, final ImageView m1) {

 e1.addTextChangedListener(new TextWatcher() {

 @Override
 public void onTextChanged(CharSequence s, int start, int before,
  int count) {
 // TODO Auto-generated method stub

 }

 @Override
 public void beforeTextChanged(CharSequence s, int start, int count,
  int after) {
 // TODO Auto-generated method stub

 }

 @Override
 public void afterTextChanged(Editable s) {
 // TODO Auto-generated method stub
 // 監(jiān)聽如果輸入串長度大于0那么就顯示clear按鈕。
 String s1 = s + "";
 if (s.length() > 0) {
  m1.setVisibility(View.VISIBLE);
 } else {
  m1.setVisibility(View.INVISIBLE);
 }

 }
 });

 m1.setOnClickListener(new OnClickListener() {

 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 // 清空輸入框
 e1.setText("");

 }
 });

 }

}

主程序代碼

public class MainActivity extends Activity {
 EditText e1, e2;
 ImageView m1, m2;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 requestWindowFeature(Window.FEATURE_NO_TITLE);
 setContentView(R.layout.activity_user_login);
 init();
 }

 private void init() {
 // TODO Auto-generated method stub
 e1 = (EditText) findViewById(R.id.phonenumber);
 e2 = (EditText) findViewById(R.id.password);
 m1 = (ImageView) findViewById(R.id.del_phonenumber);
 m2 = (ImageView) findViewById(R.id.del_password);
 // 添加清楚監(jiān)聽器大氣
 EditTextClearTools.addclerListener(e1, m1);
 EditTextClearTools.addclerListener(e2, m2);

 }

}

xml對于安卓程序的重要性相信大家在開發(fā)的路程中會慢慢體會到。在這里僅僅是給了一個簡單的例子,后面會更新很多很好的安卓技術(shù)博客。我是安卓天,感謝大家支持。希望大家多多溝通交流。

代碼連接:源碼下載

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • android實現(xiàn)定時拍照功能

    android實現(xiàn)定時拍照功能

    這篇文章主要為大家詳細(xì)介紹了android實現(xiàn)定時拍照功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • 簡單實用的Android UI微博動態(tài)點贊效果

    簡單實用的Android UI微博動態(tài)點贊效果

    這篇文章主要為大家詳細(xì)介紹了簡單實用的Android UI微博動態(tài)點贊效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Android 改變圖標(biāo)原有顏色和搜索框的實例代碼

    Android 改變圖標(biāo)原有顏色和搜索框的實例代碼

    讓Android也能有iOS那么方便的圖片色調(diào)轉(zhuǎn)換,就像同一個圖標(biāo),但是有多個地方使用,并且顏色不一樣,就可以用這個方法了。 本文實現(xiàn)TextView圖片和文字居中,鍵盤搜索功能,具體實現(xiàn)代碼大家跟隨腳本之家小編看看吧
    2017-09-09
  • Android實現(xiàn)多點觸控,自由縮放圖片的實例代碼

    Android實現(xiàn)多點觸控,自由縮放圖片的實例代碼

    本篇文章主要介紹了Android實現(xiàn)多點觸控,自由縮放圖片的實例代碼,可以自由地對圖片進(jìn)行縮放和移動,非常具有實用價值,需要的朋友可以參考下。
    2016-12-12
  • Android開發(fā)中Intent傳遞對象的方法分析

    Android開發(fā)中Intent傳遞對象的方法分析

    這篇文章主要介紹了Android開發(fā)中Intent傳遞對象的方法,結(jié)合實例分析了Intent傳遞對象所涉及的具體方法、實現(xiàn)步驟與相關(guān)注意事項,需要的朋友可以參考下
    2016-02-02
  • Android實現(xiàn)文件資源管理器雛形

    Android實現(xiàn)文件資源管理器雛形

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)文件資源管理器雛形,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Android 處理 View 重復(fù)點擊的多種方法

    Android 處理 View 重復(fù)點擊的多種方法

    這篇文章主要介紹了Android 處理 View 重復(fù)點擊的多種方法,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-03-03
  • Android 使用 okhttp3和retrofit2 進(jìn)行單文件和多文件上傳

    Android 使用 okhttp3和retrofit2 進(jìn)行單文件和多文件上傳

    這篇文章主要介紹了Android 使用 okhttp3和retrofit2 進(jìn)行單文件和多文件上傳,開發(fā)項目中需要進(jìn)行單文件多文件的上傳功能,下面演示的ApiResponse是自己分裝的返回值,要根據(jù)自己的項目來完成,需要的朋友可以參考下
    2022-10-10
  • Android開發(fā)導(dǎo)入項目報錯Ignoring InnerClasses attribute for an anonymous inner class的解決辦法

    Android開發(fā)導(dǎo)入項目報錯Ignoring InnerClasses attribute for an anonym

    今天小編就為大家分享一篇關(guān)于Android開發(fā)導(dǎo)入項目報錯Ignoring InnerClasses attribute for an anonymous inner class的解決辦法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • Android后臺定時提醒功能實現(xiàn)

    Android后臺定時提醒功能實現(xiàn)

    這篇文章主要介紹了Android后臺定時提醒功能,針對Service,AlarmManager的使用進(jìn)行詳細(xì)闡述,感興趣的小伙伴們可以參考一下
    2016-01-01

最新評論

庄浪县| 阿合奇县| 吴桥县| 温宿县| 化州市| 东乌珠穆沁旗| 双辽市| 河源市| 湟源县| 广丰县| 嘉鱼县| 龙口市| 修水县| 彩票| 赤城县| 庄河市| 玉屏| 武义县| 锡林郭勒盟| 鹤山市| 莱阳市| 安平县| 民乐县| 迭部县| 津市市| 贡觉县| 长乐市| 滦平县| 阳春市| 阿尔山市| 博兴县| 崇礼县| 和平县| 威宁| 即墨市| 宿州市| 博乐市| 大同县| 昭通市| 仙居县| 丁青县|