-
子類控件在LinearLayout中常用到的屬性
查看全部 -
Android 結(jié)構(gòu)
查看全部 -
src/存放java源代碼
查看全部 -
LinearLayout常用屬性
查看全部 -
使用RadioGroup和RadioButton
<RadioGroup android:?id="@+id/radioGroup1" android:?layout_width="wrap_content" android:?layout_height="wrap_content" android:?orientation="horizontal" > ????<RadioButton ????android:?id="@+id/radio0" ????android:?layout_width="wrap_content" ????android:?layout_height="wrap_content" ????android:?checked="true" ????android:?text="女"?/> ????<RadioButton ????android:?id="@+id/radio1" ????android:?layout_width="wrap_content" ????android:?layout_height="wrap_content" ????android:?checked="true" ????android:?text="男"?/> </RadioGroup>
實(shí)現(xiàn)方式
import?android.widget.RadioGroup; public?class?MainActivity?extends?Activity?implements?OnCheckedChangeListener{ ????private?RadioGroup?rg; ????@Override ????protected?void?onCreate(Bundle?savedInstanceState)?{ ????????????super.onCreate(savedInstanceState); ????????????setContentView(R.layout.activity_main); ????????????rg?=?(RadioGroup)?findViewById(R.id.radioGroup1); ????????????/* ?????????????*實(shí)現(xiàn)RadioGroup的監(jiān)聽(tīng)事件 ?????????????* ?????????????*/ ????????????rg.setOnCheckedChangeListener(this); ????????} ????????@Override ????????public?void?onCheckedChanged(RadioGroup?group,?int?checkedId)?{ ????????switch?(checkedId)?{ ????????????case?R.id.radio0: ????????????Log.i("tag",?"你是女的"); ????????????break; ????????????case?R.id.radio1: ????????????Log.i("tag",?"你是男的"); ????????????break; ????????} ????} }
查看全部 -
RadioGroup 和 RadioButton
RadioButton選中后不能取消
查看全部 -
使用checkBox
布局文件
<CheckBox android:?checked="false" android:?id="@+id/checkBox1" android:?layout_width="wrap_content" android:?layout_height="wrap_content" android:?text="籃球"?/> <CheckBox android:?checked="false" android:?id="@+id/checkBox2" android:?layout_width="wrap_content" android:?layout_height="wrap_content" android:?text="足球"?/> <CheckBox android:?checked="false" android:?id="@+id/checkBox3" android:?layout_width="wrap_content" android:?layout_height="wrap_content" android:?text="排球"?/>
實(shí)現(xiàn)方式
public?class?MainActivity?extends?Activity?{ ????private?CheckBox?checkBox; ????@Override ????protected?void?onCreate(Bundle?savedInstanceState)?{ ????????super.onCreate(savedInstanceState); ????????setContentView(R.layout.activity_main); ????????//初始化checkBox ????????checkBox?=?(CheckBox)?findViewById(R.id.checkBox1); ????????//通過(guò)設(shè)置checkBox的監(jiān)聽(tīng)事件來(lái)對(duì)checkBox是不是被選中(用匿名內(nèi)部類來(lái)實(shí)現(xiàn)) ????????checkBox.setOnCheckedListener(new?OnCheckedChangeListener()?{ ????????????@Override ????????????public?void?onCheckedChanged(CompoundButton?buttonView,?boolean?isChecked)?{,? ????????????????Log.i("tag",?isChecked+""); ????????????????//通過(guò)onCheckedChanged來(lái)監(jiān)聽(tīng)當(dāng)前的checkBox是否被選中 ????????????????if(isChecked)?{ ????????????????????String?text?=?checkBox.getText().toString(); ????????????????????Log.i("tag",?text); ????????????????} ????????????} ????????}); ????} }
查看全部 -
CheckBox復(fù)選框
查看全部 -
ToggleButton按鈕實(shí)現(xiàn)開(kāi)關(guān)效果
布局文件
<ToggleButton android:?id="@+id/toggleButton1" android:?layout_width="match_parent" android:?layout_height="wrap_content" android:?textOn="開(kāi)" android:?textOff="關(guān)" > </ToggleButton> <ImageView android:?id="@+id/imageView1" android:?layout_width="match_parent" android:?layout_height="match_parent" android:?background="@drawable/off" > </lmageView>
實(shí)現(xiàn)方式
——————————
private?ToggleButton?tb; private?ImageView?img;
————————
初始化控件
tb?=?(ToggleButton)?findViewById(R.id.toggleButton1); img?=?(ImageView)?findViewById(R.id.imageView1);
————————
給當(dāng)前的tb設(shè)置監(jiān)聽(tīng)器(用接口的方式實(shí)現(xiàn))
public?class?MainActivity?extends?Activity?implements?OnCheckedChangeListener
@Override public?void?onCheckedChanged(CompoundButton?buttonView,?boolean?isChecked)?{}
tb.setOnCheckedChangeListener(this);
————————
@Override public?void?onCheckedChanged(CompoundButton?buttonView,?boolean?isChecked)?{ /* *當(dāng)tb被點(diǎn)擊的時(shí)候,當(dāng)前的方法會(huì)執(zhí)行 *buttonView---代表被點(diǎn)擊控件的本身 *isChecked---代表被點(diǎn)擊的控件的狀態(tài) *當(dāng)點(diǎn)擊這個(gè)tb的時(shí)候,更換img的背景 */ img.setBackgroundResource(isChecked?R.drawable.on:R.drawable.off); }
查看全部 -
ToggleButton
查看全部 -
使用MultiAutoCompletementTextView實(shí)現(xiàn)自動(dòng)匹配輸入內(nèi)容
布局文件:
<MultiAutoCompleteTextView
android: id="@+id/multiAutoCompleteTextView1"
android: completionThreshold="3"
android: layout_width="match_parent"
android: layout_height="wrap_content"
android: hint="請(qǐng)輸入你的收件人"
>
</MultiAutoCompleteTextView>
實(shí)現(xiàn)方式:
————————————
第一步:初始化控件
private MultiAutoCompleteTextView macTextView;
macTextView = (MultiAutoCompleteTextView)findViewById(R.id.multiAutoCompleteTextView1);
————————————
第二步:需要一個(gè)適配器
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ?res);
————————————
第三步:初始化數(shù)據(jù)源——這些數(shù)據(jù)源去匹配文本框輸入的內(nèi)容
private String[] res = {"beijing1", "beijing2", "beijing3", "shanghai1", "shanghai2"}
————————————
第四步:講adapter與當(dāng)前的MultiAutoCompleteTextView綁定
macTextView.setAdapter(adapter);
————————————
第五步:設(shè)置分隔符
設(shè)置以逗號(hào)為分隔符為結(jié)束的符號(hào)
macTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
————————————
MultiAutoCompleteTextView與AutoCompleteTextView的區(qū)別:
act適合用于搜索引擎,不支持多次匹配
mact適合用于發(fā)送郵件,支持多次匹配
查看全部 -
MultiAutoCompleteTextView
查看全部 -
使用AutoCompleteTextView實(shí)現(xiàn)自動(dòng)匹配輸入的內(nèi)容
布局文件:
<AutoCompleteTextView
android: id="@+id/autoCompleteTextView1"
android: completionThreshold="3"
android: layout_width="match_parent"
android: layout_height="wrap_content"
android: hit="請(qǐng)輸入你要搜索的關(guān)鍵詞"
>
</AutoCompleteTextView>
————————————
第一步:初始化控件
private AutoCompleteTextView acTextView;
acTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
————————————
第二步:需要一個(gè)適配器
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ?res);
————————————
第三步:初始化數(shù)據(jù)源—這數(shù)據(jù)源去匹配文本框輸入的內(nèi)容
private String[] res = {"beijing1", "beijing2", "beijing3", "shanghai1", "shanghai2"}
————————————
第四步:將adapter與當(dāng)前AutoCompleteTextView綁定
acTextView.setAdapter(adapter);
查看全部 -
AutoCompleteTextView
查看全部 -
單行顯示文本
android: singleLine="true"
跑馬燈實(shí)現(xiàn)方法(一、用在單個(gè)文本)
android: ellipsize="marquee"
android: focusable="true"
android: focusableInTouchMode="true"
跑馬燈實(shí)現(xiàn)方法(二、可以用于多個(gè)文本)
新建自定義控件類(如圖)
查看全部
舉報(bào)