1.1.1文本控件(TextView和EditText)
在android中文本控件分为:TextView控件和EditText控件EditText控件继承自TextView。EditText与TextView最大的不同是EditText是可以编辑的。
ImageButton继承自ImageView。ImageButton与Button最大的区别是ImageButton没有text属性,既按钮中将显示图片而不是文本。ImageButton控件中设置显示图片可以通过android:src属性,也可以通过setImageResurce(int)方法来实现。
ToggleButton也具有一些自己的ToggleButton属性。
CheckBox和RadioButton都是继承自CompoundButton中继承了一些成员
1.1.5图片控件(ImageView)
ImageView控件负责显示图片,其图片来源既可以是资源文件的id,也可以是 Drawable对象或Bitmap对象,还可以是ContentProvider的Uri。
<?xmlversion="1.0"encoding="utf-8"?> <resources> <declare-styleablename="MRadioButton"> <attrname="value"format="string"/> </declare-styleable> </resources>
package com.jabony.customerview; import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.RadioButton; public class MRadioButton extends RadioButton implements OnCheckedChangeListener { private String mValue; public MRadioButton(Context context) { super(context); } public MRadioButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public String getValue() { return this.mValue; } public void setValue(String value) { this.mValue = value; } public MRadioButton(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MRadioButton); this.mValue = a.getString(R.styleable.MRadioButton_value); invalidate(); a.recycle(); setOnCheckedChangeListener(this); } @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:key="http://schemas.android.com/apk/res/com.jabony.customerview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.jabony.customerview.MRadioButton android:id="@+id/mRadioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name" android:textSize="24sp" key:value="true" > </com.jabony.customerview.MRadioButton> </LinearLayout>