天天看點

Android控件——TextView、EditText、ImageView、Button、ImageButton

  1. TextView——顯示文本框控件

    TextView控件的常用屬性

    • android:id——控件的id
    • android:layout_width——控件的寬度
    • android:layout_hight——控件的高度
    • android:text——文本内容
    • android:textSize——文本大小
    • android:textColor—文本顔色
    • android:backgound——控件背景

    wrap_content:包裹實際文本内容

    match_parent:目前控件鋪滿父類容器:2.3api之後添加的一個屬性值

    fill_parent:目前控件鋪滿父類容器:在2.3api之前的一個屬性值

2.EditText——輸入文本框

TextView控件的常用屬性
           
  • android:id——控件的id
  • android:layout_width——控件的寬度
  • android:layout_hight——控件的高度
  • android:text——文本内容
  • android:textSize——文本大小
  • android:textColor—文本顔色
  • android:backgound——控件背景
  • android:hint——提示輸入文本
  • android:inputType—文本類型

3.ImageView——顯示圖檔的控件

ImageView屬性
           
  • android:src=”@drawable/ic_launcher”——ImageView的圖檔内容
  • android:background=”@drawable/ic_launcher”——ImageView背景圖檔
  • android:background=”#00ff00”——ImageView的RGB顔色

4.Button——按鈕

<Button
 android:id="@+id/button1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="Button" 
/>
           

特征:

  • 可以作為一個按鈕産生明顯的點選事件
  • Button有text屬性,無src屬性,text當中的字元串一般是存放在value當中的string資源
  • 産生明顯的點選效果
  • 和smallButton一樣,隻不過smallButton多一條style屬性, style=”?android:attr/buttonStyleSmall”,它調用了系統下面的一個風格

5.ImageButton——圖檔按鈕

<ImageButton
 android:id="@+id/imagebutton1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:src="@drawablebc_ab_share_pack_holo_light" 
/>
           

特征:

  • 可以作為一個按鈕産生明顯的點選事件
  • ImageButton有src屬性,無text屬性,不可以設定文本内容,background以及src添加一個image,目前圖檔上可以做一個有文本内容的圖檔
  • 産生明顯的點選效果