五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網 會員登陸 & 注冊

Android開發(fā)學習教程(8)- Android EditText用法和屬性

2023-01-26 15:23 作者:考研保研直通車  | 我要投稿

上一篇我們詳細講了Button點擊事件的原理,這里來學習EditText的基本用法。

EditText是什么

EditText文本輸入框,比如我們常見的帳號輸入框,密碼輸入框等等。

EditText有什么用

程序與用戶交互的一種方式,接收用戶輸入的內容。

EditText怎么用

繼續(xù)基于上一篇的項目,我們增加一個帳號輸入框,手機號輸入框,密碼輸入框:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?xml?version="1.0"?encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????xmlns:app="http://schemas.android.com/apk/res-auto"
????xmlns:tools="http://schemas.android.com/tools"
????android:layout_width="match_parent"
????android:layout_height="match_parent"
????tools:context=".TestActivity">
????<TextView
????????android:id="@+id/textView"
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:layout_marginTop="40dp"
????????android:background="#cccccc"
????????android:singleLine="true"
????????android:text="Hello Activity Hello Activity Hello Activity Hello Activity"
????????android:textColor="#FF0000"
????????android:textSize="20sp"
????????app:layout_constraintEnd_toEndOf="parent"
????????app:layout_constraintHorizontal_bias="0.0"
????????app:layout_constraintStart_toStartOf="parent"
????????app:layout_constraintTop_toTopOf="parent"?/>
????<Button
????????android:id="@+id/button"
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:layout_marginTop="20dp"
????????android:text="Button"
????????app:layout_constraintEnd_toEndOf="parent"
????????app:layout_constraintStart_toStartOf="parent"
????????app:layout_constraintTop_toBottomOf="@+id/textView"?/>
????<EditText
????????android:id="@+id/et_account"
????????android:layout_width="match_parent"
????????android:layout_height="wrap_content"
????????android:layout_marginTop="20dp"
????????android:hint="請輸入賬號"
????????app:layout_constraintEnd_toEndOf="parent"
????????app:layout_constraintStart_toStartOf="parent"
????????app:layout_constraintTop_toBottomOf="@+id/button"?/>
????<EditText
????????android:id="@+id/et_phone"
????????android:layout_width="match_parent"
????????android:layout_height="wrap_content"
????????android:layout_marginTop="20dp"
????????android:hint="請輸入手機號"
????????android:inputType="number"
????????app:layout_constraintEnd_toEndOf="parent"
????????app:layout_constraintStart_toStartOf="parent"
????????app:layout_constraintTop_toBottomOf="@+id/et_account"?/>
????<EditText
????????android:id="@+id/et_password"
????????android:layout_width="match_parent"
????????android:layout_height="wrap_content"
????????android:layout_marginTop="20dp"
????????android:hint="請輸入密碼"
????????android:inputType="textPassword"
????????app:layout_constraintEnd_toEndOf="parent"
????????app:layout_constraintStart_toStartOf="parent"
????????app:layout_constraintTop_toBottomOf="@+id/et_phone"?/>
</androidx.constraintlayout.widget.ConstraintLayout>

上面我們添加了三個EditText分別是帳號輸入框,手機號輸入框,密碼輸入框:

帳號輸入框:

1
2
3
4
5
6
7
8
9
<EditText
????android:id="@+id/et_account"
????android:layout_width="match_parent"
????android:layout_height="wrap_content"
????android:layout_marginTop="20dp"
????android:hint="請輸入賬號"
????app:layout_constraintEnd_toEndOf="parent"
????app:layout_constraintStart_toStartOf="parent"
????app:layout_constraintTop_toBottomOf="@+id/button"?/>

其中 android:hint 是輸入框中的提示文字信息,在我們輸入文本之前或者清空輸入的文本之后會顯示出來。

手機號輸入框:

1
2
3
4
5
6
7
8
9
10
<EditText
????android:id="@+id/et_phone"
????android:layout_width="match_parent"
????android:layout_height="wrap_content"
????android:layout_marginTop="20dp"
????android:hint="請輸入手機號"
????android:inputType="number"
????app:layout_constraintEnd_toEndOf="parent"
????app:layout_constraintStart_toStartOf="parent"
????app:layout_constraintTop_toBottomOf="@+id/et_account"?/>

其中 android:inputType=”number” 是規(guī)定輸入框內只能輸入數(shù)字。

密碼輸入框:

1
2
3
4
5
6
7
8
9
10
<EditText
????android:id="@+id/et_password"
????android:layout_width="match_parent"
????android:layout_height="wrap_content"
????android:layout_marginTop="20dp"
????android:hint="請輸入密碼"
????android:inputType="textPassword"
????app:layout_constraintEnd_toEndOf="parent"
????app:layout_constraintStart_toStartOf="parent"
????app:layout_constraintTop_toBottomOf="@+id/et_phone"?/>

其中 android:inputType=”textPassword” 表示輸入框輸入類型為文本密碼類型,可以輸入任意類型的內容,但是輸入之后顯示的是*****。

EditText其他屬性:

1
2
3
4
5
android:textColorHint="#95A1AA"? 提示信息文字的字體顏色
android:textColor = "#ff8c00"??? 輸入內容的字體顏色
android:singleLine="true"??????? 單行輸入,一旦設置為true,則文字不會自動換行
android:background="@null"?????? 控件背景,@null表示背景透明
android:editable="false"???????? 輸入框不可編輯

源碼鏈接:https://yunjunet.cn/876738.html

Android開發(fā)學習教程(8)- Android EditText用法和屬性的評論 (共 條)

分享到微博請遵守國家法律
宣城市| 北安市| 乾安县| 阿拉尔市| 洪雅县| 遵义县| 保康县| 绿春县| 布尔津县| 宝鸡市| 孝昌县| 长垣县| 调兵山市| 金塔县| 宝兴县| 尉氏县| 仙居县| 宁都县| 泰安市| 乐都县| 五家渠市| 宝山区| 诸暨市| 靖江市| 贞丰县| 荣成市| 鹿泉市| 丹江口市| 尚义县| 邻水| 阿拉善左旗| 南澳县| 神池县| 新邵县| 南川市| 博野县| 内黄县| 临沧市| 石家庄市| 新郑市| 绥阳县|