Android開發教學
Android 開發環境配置
Android 架構
Android 應用組件
Android Hello World示例
Android 資源組織和訪問
Android Activity
Android Service
Android廣播接收器
Android內容提供者
Android碎片/片段
Android Intent過濾器
Android UI佈局
Android LinearLayout
Android RelativeLayout
Android TableLayout
Android AbsoluteLayout
Android FrameLayout
Android ListView
Android GridView
Android UI控件
Android TextView
Android EditText
Android AutoCompleteTextView
Android Button
Android ImageButton
Android CheckBox
Android ToggleButton
Android RadioButton
Android RadioGroup
Android事件處理
Android樣式和主題
Android樣式示例
Android主題示例
Android自定義組件
Android拖放
Android通知
Android基於位置服務
Android發送電子郵件
Android發送短信/SMS
Android撥打電話
發佈Android應用
ArrayAdapter
SimpleCursorAdapter
Android ProgressDialog
Android Spinner
使用活動代碼自定義Android組件
使用佈局文件自定義Android組件
Android自定義組件及屬性
Android Alertdialog(警告對話框)
Android Animation(動畫)實例
Android音頻捕獲(錄音)
Android音頻管理器實例
Android AutoCompleteTextView(自動完成)實例
Android最佳實踐
Android Bluetooth(藍牙)實例
Android Camera(攝像頭)
Android Clipboard(複製/剪貼板)
Android自定義字體
Android數據備份
Android Gestures/手勢
Android圖片效果
Android圖片切換
Android內部存儲
Android JetPlayer實例
Android JSON解析器
Android加載Spinner
Android本地化
Android登錄實例
Android MediaPlayer(多媒體播放)

Android UI控件

Android應用程序的用戶界面是一切,用戶可以看到並與之交互。已經解了並用它定位在活動中的各種視圖的佈局。本章會給詳細視圖的各方面。

視圖(View)是一個對象繪製在屏幕上,用戶可以互動的東西,ViewGroup 是一個對象,其中包含其他View(ViewGroup)的對象,並可以定義用戶界面的佈局。

視圖可以定義在一個XML文件,它提供了一個人類可讀的結構佈局,類似於HTML佈局。例如,一個簡單的垂直佈局,文本視圖(TextView)和按鈕(Button)看起來像這樣:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="I am a TextView" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="I am a Button" />

Android UI控件

有一些 Android 提供的UI控件,允許建立應用程序的圖形用戶界面。

S.N.

UI控件與說明

1

TextView
這種控制用於顯示文本給用戶。

2

EditText
EditText是TextView預定義的子類,包括豐富的編輯功能。

3

AutoCompleteTextView
AutoCompleteTextView是一個視圖,它類似於EditText,不同之處是在用戶鍵入時,它會顯示自動完成建議的列表。

4

Button
按鈕式可以被按壓,或者點擊 - 由用戶執行動作。

5

ImageButton
AbsoluteLayout使可以指定其子視圖的確切位置。

6

CheckBox
可以由用戶來切換開/關。提供一組可選擇的選項並不相互排斥時候呈現用戶,應該使用複選框。

7

ToggleButton
一個開/關按鈕帶有指示燈。

8

RadioButton
單選按鈕有兩種狀態:選中或取消選中。

9

RadioGroup
RadioGroup用於組織一個或多個單選按鈕。

10

ProgressBar
進度條視圖(ProgressBar)提供一些日常任務,當在後臺執行任務時,給出視覺反饋。

11

Spinner
一個下拉列表,允許用戶選擇從一組一個值(類似HTML中的select)

12

TimePicker
TimePicker視圖允許用戶選擇一天中的時間,在24小時模式或AM/ PM模式。

13

DatePicker
TimePicker視圖允許用戶選擇一天中的時間,在24小時模式或AM/PM模式。

創建UI控件

正如在前面的章節中,視圖對象可能有一個唯一的ID分配給,這個唯一識別視圖樹內。一個視圖ID在XML標籤的語法是:

android:id="@+id/text_id"

要創建一個用戶界面控件/視圖/小工具,必須在佈局文件中定義一個視圖/部件,並將其分配一個唯一的ID如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/text_id" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="I am a TextView" />

最後控制對象創建一個實例,並獲得它的佈局,使用以下命令:

TextView myText = (TextView) findViewById(R.id.text_id);