Android控制項——Button與ImageButton

來源:互聯網
上載者:User

標籤: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

聯繫我們

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