跟我學android-常用控制項之EditText,android-edittext

來源:互聯網
上載者:User

跟我學android-常用控制項之EditText,android-edittext

EditText 是TextView的直接子類,它與TextView的區別在於,EditText可以接受使用者輸入。

下面通過一個執行個體來說明EditText的用法

執行個體:sina 微博的登入介面(注意,由於 我們還沒有接觸 按鈕 和圖片的控制項,所以 按鈕盒圖片的地方 我們使用TextView 做)

首先看sina 微博登入頁面的

由於該是我從iphone上截取下來的,sina 微博android版本的背景不是這張,所以 我更換了背景圖

代碼如下

1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:background="@drawable/login_wallpaper1" 6 android:orientation="vertical" > 7 8 <!-- 帳戶圖片 --> 9 10 <TextView11 android:layout_width="wrap_content"12 android:layout_height="wrap_content"13 android:layout_gravity="center_horizontal"14 android:layout_marginBottom="10dp"15 android:layout_marginTop="20dp"16 android:background="@drawable/login_profile_default" />17 <!-- 使用者名稱和密碼輸入框,使用嵌套布局 -->18 19 <LinearLayout20 android:layout_width="match_parent"21 android:layout_height="wrap_content"22 android:layout_margin="10dp"23 android:background="@drawable/fast_select_merchant_input_bg"24 android:orientation="vertical" >25 26 <EditText27 android:id="@+id/et_user"28 android:layout_width="match_parent"29 android:layout_height="wrap_content"30 android:background="@null"31 android:drawableLeft="@drawable/login_user"32 android:drawablePadding="15dp"33 android:hint="郵箱/手機號"34 android:padding="10dp" />35 <!-- 分割線 -->36 37 <View38 android:layout_width="match_parent"39 android:layout_height="1dp"40 android:background="@android:color/darker_gray" />41 42 <EditText43 android:id="@+id/et_pwd"44 android:layout_width="match_parent"45 android:layout_height="wrap_content"46 android:background="@null"47 android:drawableLeft="@drawable/login_key"48 android:drawablePadding="15dp"49 android:hint="請輸入密碼"50 android:inputType="textPassword"51 android:padding="10dp" />52 </LinearLayout>53 <!-- 類比登入按鈕 -->54 55 <TextView56 android:layout_width="match_parent"57 android:layout_height="wrap_content"58 android:layout_margin="10dp"59 android:background="#006400"60 android:gravity="center"61 android:padding="10dp"62 android:text="登入"63 android:textColor="#F8F8FF"64 android:textSize="30sp" />65 66 </LinearLayout>View Code

 


布局是可以嵌套布局的,在這個登入頁面中 我的輸入框部分採取的是 嵌套一個 線性布局。

 

大家可以預覽一下效果。

 


android中怎接收從edit text控制項輸入的內容

EditText editText=(EditText)findViewById(R.id.***);//前提是在布局檔案裡你已經註冊了這個控制項,***就是註冊的這個控制項的id
String s=editText.getText().toString();//變數s中儲存的就是文字框中輸入的內容
 
android怎獲得彈出的對話方塊中的edit text控制項的資料

先獲得dialog,再根據找到edit text 控制項,最後根據edittext.getText方法獲得控制項的資料。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.