Android中提供了兩種按鈕組件,一種是普通按鈕,另一種是圖片按鈕。這兩種按鈕的都是用於在UI界面上生成一個可以單擊的按鈕。當用戶單擊按鈕時,將會觸發一個onClick事件,可以通過爲按鈕添加單擊事件監聽器指定所要觸的動作。
1.普通按鈕
<Button
android:text="顯示文本"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</Button>
2.圖片按鈕
<ImageButton
android:id="@+id/imageButton1"
android:src="@drawable/圖片文件名"
android:background="#F000"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageButton>