標籤:lfs bdr abap aam 漢字 dfs cWeb kth zed
1.簡單介紹
2.特徵
3.實現Button和ImageButton3.1使用Button
布局檔案定義Button
strings.xml定義常量(漢字一般定義在strings.xml中,布局檔案中通過@string/name引用)
原理: res資源檔下的檔案都會在gen目錄下R.java中產生一個id,唯一標識一個資源。
效果:
3.1使用ImageButton
布局檔案:背景顏色設為黑色,通過src引用圖片(高度為包裹圖片大小),如果通過background引入圖片是圖片適應按鈕大小
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button_name" /> <ImageButton android:id="@+id/imageButton1" android:layout_width="match_parent" android:background="#000000" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /></LinearLayout>
效果:
總結:
button可以設定文字,不可以設定圖片
ImageButton 可以設定圖片,如果希望設定文字可以通過background或者src引入一個帶文字的圖片實現文字按鈕效果。
Android控制項——Button與ImageButton