一、基本控件介绍


一般新建组件有两种方式:XML中定义和Java代码实现,一般XML中定义较为常用。

1.Button


按钮,在main.xml中定义如下:

[html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><Button
  2. <spanstyle="WHITE-SPACE:pre"></span>android:layout_width="wrap_content"<!--按钮宽度匹配文本的大小-->
  3. android:layout_height="wrap_content"<!--按钮高度匹配文本大小-->
  4. android:text="文本"<!--按钮的文本-->
  5. android:id="@+id/button1"<!--按钮的id-->
  6. ></Button></span>

Button的监听器:onClickListener;

需要实现方法:public void onClick(View v);v表示触发的控件,比如按钮

代码示例:实现点击按钮生成随机数;


ButtonActivity.java

[java] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';">packageorg.xiazdong;
  2. importjava.util.Random;
  3. importandroid.app.Activity;
  4. importandroid.app.AlertDialog;
  5. importandroid.app.AlertDialog.Builder;
  6. importandroid.os.Bundle;
  7. importandroid.view.View;
  8. importandroid.view.View.OnClickListener;
  9. importandroid.widget.Button;
  10. importandroid.widget.TextView;
  11. importandroid.widget.Toast;
  12. publicclassButtonActivityextendsActivityimplementsOnClickListener{//实现点击监听器
  13. privateButtonbutton;
  14. privateTextViewtv;
  15. @Override
  16. publicvoidonCreate(BundlesavedInstanceState){
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.main);
  19. button=(Button)findViewById(R.id.button1);//根据ID找组件
  20. tv=(TextView)findViewById(R.id.tv);
  21. button.setOnClickListener(this);//为button设置监听器
  22. }
  23. @Override
  24. publicvoidonClick(Viewview){
  25. Stringstr=newRandom().nextInt()+"";
  26. tv.setText(str);
  27. Toast.makeText(this,"点击了按钮!!",Toast.LENGTH_SHORT).show();//设置提示信息
  28. Builderbuilder=newAlertDialog.Builder(this);//创建对话框
  29. builder.setTitle("提示信息").setMessage("点击了按钮,随机数为:"+str).show();//设置对话框属性并显示
  30. }
  31. }</span>


main.xml

[html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical">
  6. <TextView
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:text=""
  10. android:id="@+id/tv"
  11. />
  12. <Button
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:text="点击生成随机数"
  16. android:id="@+id/button1"
  17. ></Button>
  18. </LinearLayout></span>

2.ImageButton


和Button的区别为背景可以自定义图片,在main.xml中定义如下:

[html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><ImageButton
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:id="@+id/ib1"
  5. android:background="@drawable/ic_launcher"/><!--设置按钮的背景为drawable文件夹下的ic_launcher图片--></span>


代码示例:实现点击图片按钮就切换图片;


main.xml [html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical">
  6. <TextView
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:text="@string/hello"/>
  10. <ImageButton
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:id="@+id/ib1"
  14. android:background="@drawable/ic_launcher"/>
  15. </LinearLayout></span>

ImageButtonActivity.java

[java] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';">packageorg.xiazdong;
  2. importandroid.app.Activity;
  3. importandroid.os.Bundle;
  4. importandroid.view.MotionEvent;
  5. importandroid.view.View;
  6. importandroid.view.View.OnTouchListener;
  7. importandroid.widget.ImageButton;
  8. publicclassImageButtonActivityextendsActivity{
  9. privateImageButtonib1;
  10. @Override
  11. publicvoidonCreate(BundlesavedInstanceState){
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.main);
  14. ib1=(ImageButton)findViewById(R.id.ib1);
  15. ib1.setOnTouchListener(newOnTouchListener(){
  16. @Override
  17. publicbooleanonTouch(Viewv,MotionEventevent){
  18. if(event.getAction()==MotionEvent.ACTION_DOWN){//按下按钮时
  19. ib1.setBackgroundResource(R.drawable.logo);
  20. }
  21. elseif(event.getAction()==MotionEvent.ACTION_UP){//抬起按钮时
  22. ib1.setBackgroundResource(R.drawable.ic_launcher);
  23. }
  24. returnfalse;
  25. }
  26. });
  27. }
  28. }</span>

3.EditText


文本框,在main.xml中定义如下:

[html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><EditText
  2. android:id="@+id/name"
  3. android:layout_width="fill_parent"
  4. android:layout_height="wrap_content"
  5. android:hint="输入用户名..."
  6. android:inputType=""
  7. /></span>

可以在<EditText>中设置以下属性:
(1)android:inputType="number":输入类型为数字;

(2)android:maxLength="2":输入最长为2;

(3)android:singleLine="true":只能单行显示;

(4)android:password="true":输入的形式为密码
(5)android:numeric="integer":输入整数

代码示例:实现用户登录;


[html] view plain copy
  1. <p><spanstyle="font-family:'MicrosoftYaHei';"><strong>main.xml</strong>
  2. </span></p><preclass="html"name="code"><spanstyle="font-family:'MicrosoftYaHei';"><?xmlversion="1.0"encoding="utf-8"?>
  3. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:orientation="vertical">
  7. <LinearLayout
  8. xmlns:android="http://schemas.android.com/apk/res/android"
  9. android:layout_width="fill_parent"
  10. android:layout_height="wrap_content"
  11. android:orientation="horizontal">
  12. <TextView
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:text="用户名:"/>
  16. <EditText
  17. android:id="@+id/name"
  18. android:layout_width="fill_parent"
  19. android:layout_height="wrap_content"
  20. android:hint="输入用户名..."
  21. android:inputType=""
  22. />
  23. </LinearLayout>
  24. <LinearLayout
  25. xmlns:android="http://schemas.android.com/apk/res/android"
  26. android:layout_width="fill_parent"
  27. android:layout_height="wrap_content"
  28. android:orientation="horizontal">
  29. <TextView
  30. android:layout_width="wrap_content"
  31. android:layout_height="wrap_content"
  32. android:text="密码:"/>
  33. <EditText
  34. android:id="@+id/password"
  35. android:layout_width="fill_parent"
  36. android:layout_height="wrap_content"
  37. android:hint="输入密码..."
  38. android:password="true"/>
  39. </LinearLayout>
  40. <Button
  41. android:id="@+id/button"
  42. android:layout_width="fill_parent"
  43. android:layout_height="wrap_content"
  44. android:text="提交">
  45. </Button>
  46. </LinearLayout>
  47. </span></pre>
  48. <pre></pre>
  49. <spanstyle="font-family:'MicrosoftYaHei'"></span><preclass="html"name="code"><p><strong><spanstyle="font-family:'MicrosoftYaHei';">EditTextActivity.java</span></strong></p><p></p><preclass="java"name="code"><spanstyle="font-family:'MicrosoftYaHei';">packageorg.xiazdong;
  50. importandroid.app.Activity;
  51. importandroid.app.AlertDialog;
  52. importandroid.app.AlertDialog.Builder;
  53. importandroid.content.DialogInterface;
  54. importandroid.os.Bundle;
  55. importandroid.view.View;
  56. importandroid.view.View.OnClickListener;
  57. importandroid.widget.Button;
  58. importandroid.widget.EditText;
  59. publicclassEditTextActivityextendsActivity{
  60. privateEditTextname;
  61. privateEditTextpassword;
  62. privateButtonbutton;
  63. @Override
  64. publicvoidonCreate(BundlesavedInstanceState){
  65. super.onCreate(savedInstanceState);
  66. setContentView(R.layout.main);
  67. name=(EditText)findViewById(R.id.name);
  68. button=(Button)findViewById(R.id.button);
  69. password=(EditText)findViewById(R.id.password);
  70. button.setOnClickListener(newOnClickListener(){
  71. @Override
  72. publicvoidonClick(Viewv){
  73. Stringn=name.getText().toString();
  74. Stringp=password.getText().toString();
  75. Builderbuilder=newAlertDialog.Builder(EditTextActivity.this);//创建对话框
  76. builder.setTitle("提示信息").setMessage("用户名:"+n+"\n密码:"+p)
  77. .setPositiveButton("知道了",newDialogInterface.OnClickListener(){
  78. @Override
  79. publicvoidonClick(DialogInterfacedialog,intwhich){
  80. password.setText("");//清空密码
  81. }
  82. }).show();//设置对话框属性并显示
  83. }
  84. });
  85. }
  86. }</span></pre><preclass="java"name="code"><spanstyle="font-family:微软雅黑;"></span></pre>
  87. <pre></pre>
  88. <spanstyle="font-family:'MicrosoftYaHei'"></span>
  89. <pre></pre>
  90. <pre></pre>
  91. <pre></pre>
  92. <pre></pre>
  93. <pre></pre>
  94. <pre></pre>
  95. <pre></pre>
  96. <pre></pre>
  97. </pre>

4.CheckBox


多选框,在main.xml中定义如下:

[html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><CheckBox
  2. android:id="@+id/shanghai"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:text=""/></span>

onCheckedChangeListener监听器是专门对CheckBox进行监听,实现方法:public void onCheckedChanged(CompundButton buttonView,boolean isChecked);

代码示例:实现上海、北京、天津的复选框

[html] view plain copy
  1. <p><strong><spanstyle="font-family:'MicrosoftYaHei';">main.xml</span></strong></p><p></p><preclass="html"name="code"><spanstyle="font-family:'MicrosoftYaHei';"><?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical">
  6. <TextView
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:text="城市:"/>
  10. <CheckBox
  11. android:id="@+id/shanghai"
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:text="上海"/>
  15. <CheckBox
  16. android:id="@+id/beijing"
  17. android:layout_width="wrap_content"
  18. android:layout_height="wrap_content"
  19. android:text="北京"/>
  20. <CheckBox
  21. android:id="@+id/tianjing"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:text="天津"/>
  25. </LinearLayout></span></pre>
  26. <pre></pre>
  27. <spanstyle="font-family:'MicrosoftYaHei'"></span>
  28. <pre></pre>
  29. <pre></pre>
  30. <pre></pre>
  31. <pre></pre>
[html] view plain copy
  1. <p><strong><spanstyle="font-family:'MicrosoftYaHei';">CheckBoxActivity.java</span></strong></p><p></p><preclass="java"name="code"><spanstyle="font-family:'MicrosoftYaHei';">packageorg.xiazdong;
  2. importandroid.app.Activity;
  3. importandroid.os.Bundle;
  4. importandroid.widget.CheckBox;
  5. importandroid.widget.CompoundButton;
  6. importandroid.widget.CompoundButton.OnCheckedChangeListener;
  7. importandroid.widget.Toast;
  8. publicclassCheckBoxActivityextendsActivityimplements
  9. OnCheckedChangeListener{
  10. privateCheckBoxcb1,cb2,cb3;
  11. @Override
  12. publicvoidonCreate(BundlesavedInstanceState){
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.main);
  15. cb1=(CheckBox)findViewById(R.id.shanghai);
  16. cb2=(CheckBox)findViewById(R.id.beijing);
  17. cb3=(CheckBox)findViewById(R.id.tianjing);
  18. cb1.setOnCheckedChangeListener(this);
  19. cb2.setOnCheckedChangeListener(this);
  20. cb3.setOnCheckedChangeListener(this);
  21. }
  22. @Override
  23. publicvoidonCheckedChanged(CompoundButtonbuttonView,//buttonView表示改变的框,isChecked表示是选中还是取消选中
  24. booleanisChecked){
  25. if(buttonView==cb1||buttonView==cb2||buttonView==cb3){
  26. if(isChecked){
  27. Toast.makeText(this,buttonView.getText()+"被选中",Toast.LENGTH_SHORT).show();
  28. }
  29. else{
  30. Toast.makeText(this,buttonView.getText()+"取消选中",Toast.LENGTH_SHORT).show();
  31. }
  32. }
  33. }
  34. }</span></pre>
  35. <pre></pre>
  36. <pre></pre>
  37. <pre></pre>
  38. <pre></pre>
  39. <pre></pre>

5.RadioButton


单选框,在main.xml中定义如下:

[html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><RadioGroup>
  2. <RadioButton
  3. android:id="@+id/rb1"
  4. android:layout_width="fill_parent"
  5. android:layout_height="wrap_content"
  6. android:text="RadioButton1">
  7. </RadioButton>
  8. <RadioButton>
  9. </RadioButton>
  10. ......
  11. </RadioGroup></span>

在单选框中也存在一个OnCheckedChangeListener,但是不同于多选框的监听器,虽然名字一样,但是所在包不一样。

代码示例:实现“男、女”单选框;

[html] view plain copy
  1. <p><strong><spanstyle="font-family:'MicrosoftYaHei';">
  2. main.xml</span></strong></p><p></p><preclass="html"name="code"><spanstyle="font-family:'MicrosoftYaHei';"><?xmlversion="1.0"encoding="utf-8"?>
  3. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:orientation="vertical">
  7. <RadioGroup
  8. android:id="@+id/rg1"
  9. android:layout_width="fill_parent"
  10. android:layout_height="wrap_content">
  11. <RadioButton
  12. android:id="@+id/rb1"
  13. android:layout_width="fill_parent"
  14. android:layout_height="wrap_content"
  15. android:text="男">
  16. </RadioButton>
  17. <RadioButton
  18. android:id="@+id/rb2"
  19. android:layout_width="fill_parent"
  20. android:layout_height="wrap_content"
  21. android:text="女">
  22. </RadioButton>
  23. </RadioGroup>
  24. </LinearLayout></span></pre>
  25. <pre></pre>
  26. <spanstyle="font-family:'MicrosoftYaHei'"></span>
  27. <pre></pre>
  28. <pre></pre>
  29. <pre></pre>
  30. <pre></pre>
[html] view plain copy
  1. <p><strong><spanstyle="font-family:'MicrosoftYaHei';">RadioButtonActivity.java
  2. </span></strong></p><p></p><preclass="java"name="code"><spanstyle="font-family:'MicrosoftYaHei';">packageorg.xiazdong;
  3. importandroid.app.Activity;
  4. importandroid.os.Bundle;
  5. importandroid.widget.RadioButton;
  6. importandroid.widget.RadioGroup;
  7. importandroid.widget.Toast;
  8. importandroid.widget.RadioGroup.OnCheckedChangeListener;
  9. publicclassRadioButtonActivityextendsActivityimplementsOnCheckedChangeListener{
  10. /**Calledwhentheactivityisfirstcreated.*/
  11. privateRadioButtonrb1,rb2;
  12. privateRadioGrouprg;
  13. @Override
  14. publicvoidonCreate(BundlesavedInstanceState){
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.main);
  17. rb1=(RadioButton)findViewById(R.id.rb1);
  18. rb2=(RadioButton)findViewById(R.id.rb2);
  19. rg=(RadioGroup)findViewById(R.id.rg1);
  20. rg.setOnCheckedChangeListener(this);
  21. }
  22. @Override
  23. publicvoidonCheckedChanged(RadioGroupgroup,intcheckedId){
  24. if(group==rg){
  25. if(rb1.getId()==checkedId){
  26. Toast.makeText(this,rb1.getText(),Toast.LENGTH_SHORT).show();
  27. }
  28. if(rb2.getId()==checkedId){
  29. Toast.makeText(this,rb2.getText(),Toast.LENGTH_SHORT).show();
  30. }
  31. }
  32. }
  33. }</span></pre>
  34. <pre></pre>
  35. <spanstyle="font-family:'MicrosoftYaHei'"></span>
  36. <pre></pre>
  37. <pre></pre>
  38. <pre></pre>
  39. <pre></pre>


6.ProgressBar


进度条,在main.xml中定义如下:

[html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><ProgressBar
  2. android:id="@+id/pb1"
  3. style="?android:attr/progressBarStyleXxx"<!--设置进度条的样式,有大、中、小、条状-->
  4. android:layout_width="wrap_content"
  5. android:layout_height="wrap_content"/></span>

1.?andtroid:attr/progressBarStyleSmall圆形小进度条,动态
2. 默认,即不设置 圆形中等进度条,动态
3.?android:attr/progressBarStyleLarge圆形大进度条,动态
4.?android:attr/progressBarStyleHorizontal条状进度条,静态

条状进度条属性:


android:max
android:progress
android:secondaryProgress

代码示例:实现条状进度条,并当安装结束时,跳出提示


[html] view plain copy
  1. <p><strong><spanstyle="font-family:'MicrosoftYaHei';">
  2. main.xml</span></strong></p><p></p><preclass="html"name="code"><spanstyle="font-family:'MicrosoftYaHei';"><?xmlversion="1.0"encoding="utf-8"?>
  3. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:orientation="vertical">
  7. <ProgressBar
  8. android:id="@+id/pb4"
  9. style="?android:attr/progressBarStyleHorizontal"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:max="100"
  13. android:progress="0"
  14. android:secondaryProgress="0"/>
  15. </LinearLayout></span></pre>
  16. <pre></pre>
  17. <spanstyle="font-family:'MicrosoftYaHei'"></span><preclass="html"name="code"><p><strong><spanstyle="font-family:'MicrosoftYaHei';">ProgressBarActivity.java</span></strong></p><p></p><preclass="java"name="code"><spanstyle="font-family:'MicrosoftYaHei';">packageorg.xiazdong;
  18. importandroid.app.Activity;
  19. importandroid.os.Bundle;
  20. importandroid.os.Handler;
  21. importandroid.widget.ProgressBar;
  22. importandroid.widget.Toast;
  23. publicclassProgressBarActivityextendsActivityimplementsRunnable{
  24. privateProgressBarbar;
  25. privatebooleanisFinished;
  26. Threadt;
  27. Handlerhandler=newHandler();
  28. @Override
  29. publicvoidonCreate(BundlesavedInstanceState){
  30. super.onCreate(savedInstanceState);
  31. setContentView(R.layout.main);
  32. bar=(ProgressBar)findViewById(R.id.pb4);
  33. t=newThread(this);
  34. t.start();
  35. }
  36. publicvoidshowToast(){
  37. handler.post(newRunnable(){
  38. @Override
  39. publicvoidrun(){
  40. Toast.makeText(getApplicationContext(),"安装完成!",//此处需要使用Handler,因为不能在子线程中使用Toast
  41. Toast.LENGTH_SHORT).show();
  42. }
  43. });
  44. }
  45. publicvoidrun(){
  46. intcurrent=bar.getProgress();
  47. intcurrentMax=bar.getMax();
  48. intsecCurrent=bar.getSecondaryProgress();
  49. while(true){
  50. bar.setProgress(current++);
  51. bar.setSecondaryProgress(secCurrent++);
  52. if(secCurrent>=currentMax){
  53. break;
  54. }
  55. try{
  56. Thread.sleep(50);
  57. }catch(InterruptedExceptione){
  58. e.printStackTrace();
  59. }
  60. }
  61. isFinished=true;
  62. showToast();
  63. }
  64. }</span></pre>
  65. <pre></pre>
  66. <h2><aname="t16"></a><spanstyle="font-family:'MicrosoftYaHei'">7.TextView</span></h2>
  67. <spanstyle="font-family:'MicrosoftYaHei'">文本显示组件,在main.xml中定义如下:</span>
  68. <pre></pre>
  69. <pre></pre>
  70. <pre></pre>
  71. <pre></pre>
  72. <pre></pre>
  73. <pre></pre>
  74. <pre></pre>
  75. <pre></pre>
  76. </pre>


[html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><TextView
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:text="@string/hello"/><!--文本文字--></span>

8.Dialog


对话框,不需要再main.xml中显示,只需要直接在Activity中创建即可;

(1)简单的Dialog:

常用函数: setMessage() setTitle() setIcon() setPositiveButton() setNegativeButton()
[java] view plain copy
  1. Builderbuilder=newBuilder(DialogActivity.this);//创建对话框
  2. builder.setIcon(android.R.drawable.ic_dialog_info).setTitle("对话框标题");//设置对话框图标和标题
  3. builder.setMessage("对话框内容");//设置对话框信息
  4. builder.setPositiveButton("Yes",newOnClickListener(){//设置正确按钮
  5. @Override
  6. publicvoidonClick(DialogInterfacedialog,intarg1){
  7. }
  8. });
  9. builder.setNegativeButton("No",newOnClickListener(){//设置否定按钮
  10. @Override
  11. publicvoidonClick(DialogInterfacedialog,intarg1){
  12. }
  13. });
  14. builder.show();//显示对话框

(2)在dialog中添加单选框和复选框:

实例:添加“上海、北京、天津”的多选框

setMultiChoiceItems(); setSingleChoiceItems(); 注:设置这些和setMessage不能同时使用!
[html] view plain copy
  1. <preclass="java"name="code">packageorg.xiazdong;
  2. importandroid.app.Activity;
  3. importandroid.app.AlertDialog.Builder;
  4. importandroid.content.DialogInterface;
  5. importandroid.content.DialogInterface.OnMultiChoiceClickListener;
  6. importandroid.os.Bundle;
  7. publicclassDialogActivityextendsActivity{
  8. @Override
  9. publicvoidonCreate(BundlesavedInstanceState){
  10. super.onCreate(savedInstanceState);
  11. Builderbuilder=newBuilder(DialogActivity.this);
  12. builder.setMultiChoiceItems(newString[]{"上海","北京","天津"},//每项内容
  13. newboolean[]{true,false,true},//每项是否没选中
  14. newOnMultiChoiceClickListener(){//监听器
  15. @Override
  16. publicvoidonClick(DialogInterfacedialog,intwhich,
  17. booleanisChecked){
  18. }
  19. }).show();
  20. }
  21. }</pre>
  22. <pre></pre>
  23. <div><spanstyle="font-family:'MicrosoftYaHei'"></span></div>
  24. <div><spanstyle="font-family:'MicrosoftYaHei'"><strong>(3)在dialog中添加列表</strong></span></div>
  25. <div><spanstyle="font-family:'MicrosoftYaHei'"><strong></strong></span></div>
  26. <div><spanstyle="font-family:'MicrosoftYaHei'">builder.setItems(newString[]{"项1","项2"},newOnClickListener(){});</span></div>
  27. <div><spanstyle="font-family:'MicrosoftYaHei'"></span></div>
  28. <div><spanstyle="font-family:'MicrosoftYaHei'"><strong>(4)在dialog中添加视图(在main.xml中定义):</strong></span></div>
  29. <div><spanstyle="font-family:'MicrosoftYaHei'"></span></div>
  30. setView函数实现;<preclass="java"name="code">Builderbuilder=newBuilder(DialogActivity.this);
  31. Viewlayout=LayoutInflater.from(this).inflate(R.layout.main,null);
  32. builder.setIcon(android.R.drawable.ic_dialog_info).setTitle("对话框标题");
  33. builder.setMessage("对话框内容");
  34. builder.setPositiveButton("Yes",newOnClickListener(){
  35. @Override
  36. publicvoidonClick(DialogInterfacedialog,intarg1){
  37. }
  38. });
  39. builder.setNegativeButton("Yes",newOnClickListener(){
  40. @Override
  41. publicvoidonClick(DialogInterfacedialog,intarg1){
  42. }
  43. });
  44. builder.setView(layout);
  45. builder.show();
  46. </pre>
  47. <pre></pre>
  48. <pre></pre>
  49. <pre></pre>
  50. <pre></pre>

9.TabHost


分页组件,类似于如下图:



在main.xml中无需定义,直接在TabActivity中创建即可,但是TabSpec中的具体内容需要自定义,即引用布局文件中的ID;
注:
(1)Activity需要继承TabActivity 而不是Activity;
(2)OnTabChangedListener为TabHost的监听器,存在方法:public void onTagChanged(String tabId);

(3)TabSpec t1 = tabHost.newTabSpec("TabID"); (4)t1.setContent(布局或控件id); //为tabSpec添加某个布局 (5)t1.setIndicator(tab的标题);

代码示例:设置三页,每页有各自的内容

[html] view plain copy
  1. <p><strong>main.xml</strong></p><p></p><preclass="java"name="code"><?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/main"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:orientation="vertical">
  7. <LinearLayout
  8. android:id="@+id/l1"
  9. android:layout_width="fill_parent"
  10. android:layout_height="wrap_content"
  11. android:orientation="vertical">
  12. <TextView
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:text="第1页"></TextView>
  16. </LinearLayout>
  17. <LinearLayout
  18. android:id="@+id/l2"
  19. android:layout_width="fill_parent"
  20. android:layout_height="wrap_content"
  21. android:orientation="vertical">
  22. <TextView
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:text="第2页"></TextView>
  26. </LinearLayout>
  27. <LinearLayout
  28. android:id="@+id/l3"
  29. android:layout_width="fill_parent"
  30. android:layout_height="wrap_content"
  31. android:orientation="vertical">
  32. <TextView
  33. android:layout_width="wrap_content"
  34. android:layout_height="wrap_content"
  35. android:text="第3页"></TextView>
  36. </LinearLayout>
  37. </LinearLayout></pre>
  38. <pre></pre>
  39. <preclass="html"name="code"><p><strong>TabHostActivity.java</strong></p>
  40. <preclass="java"name="code">packageorg.xiazdong;
  41. importandroid.app.TabActivity;
  42. importandroid.os.Bundle;
  43. importandroid.util.Log;
  44. importandroid.view.LayoutInflater;
  45. importandroid.widget.TabHost;
  46. importandroid.widget.TabHost.OnTabChangeListener;
  47. importandroid.widget.TabHost.TabSpec;
  48. importandroid.widget.Toast;
  49. publicclassTabHostActivityextendsTabActivityimplementsOnTabChangeListener{//继承TabActivity而不是Activity
  50. TabHosthost;
  51. @Override
  52. publicvoidonCreate(BundlesavedInstanceState){
  53. super.onCreate(savedInstanceState);
  54. host=this.getTabHost();//新建TabHost
  55. LayoutInflater.from(this).inflate(R.layout.main,//将main布局文件映射成tabHost的view
  56. host.getTabContentView());
  57. TabSpect1=host.newTabSpec("t1");//新建一个页,id为t1
  58. t1.setIndicator("标签1");//设置显示页名
  59. t1.setContent(R.id.l1);//设置页的内容为l1布局,此处可以是布局或组件
  60. host.addTab(t1);//加入TabHost中
  61. TabSpect2=host.newTabSpec("t2");
  62. t2.setIndicator("标签2",getResources().getDrawable(R.drawable.ic_launcher));
  63. t2.setContent(R.id.l2);
  64. host.addTab(t2);
  65. TabSpect3=host.newTabSpec("t3");
  66. t3.setIndicator("标签3");
  67. t3.setContent(R.id.l3);
  68. host.addTab(t3);
  69. host.setOnTabChangedListener(this);//设置监听器
  70. }
  71. @Override
  72. publicvoidonTabChanged(StringtabId){
  73. Log.v("a","aaaa");
  74. if(tabId.equals("t1")){
  75. Toast.makeText(this,"标签1ing",Toast.LENGTH_LONG).show();
  76. }
  77. if(tabId.equals("t2")){
  78. Toast.makeText(this,"标签2ing",Toast.LENGTH_LONG).show();
  79. }
  80. if(tabId.equals("t3")){
  81. Toast.makeText(this,"标签3ing",Toast.LENGTH_LONG).show();
  82. }
  83. else{
  84. Toast.makeText(this,tabId,Toast.LENGTH_LONG).show();
  85. }
  86. }
  87. }</pre>
  88. <pre></pre>
  89. <pre></pre>
  90. <pre></pre>
  91. <pre></pre>
  92. <pre></pre>
  93. <pre></pre>
  94. <pre></pre>
  95. <pre></pre>
  96. <pre></pre>
  97. </pre>

10.SeekBar


拖动条,在main.xml中定义如下:
[java] view plain copy
  1. <SeekBar
  2. android:id="@+id/sb"
  3. android:layout_width="fill_parent"
  4. android:layout_height="wrap_content"
  5. />

注:存在OnSeekBarChangeListener监听器,用来监听SeekBar组件的事件,实现方法:
(1)public void onStartTrackingTouch(SeekBar seekBar); //开始移动时调用
(2)public void onStopTrackingTouch(SeekBar seekbar); //结束移动时调用
(3)public void onProgressChanged(SeekBar seekBar,int progress,boolean fromUser); //改变时调用,progress为当前值

代码示例:移动SeekBar组件,并在TextView中显示当前值

[html] view plain copy
  1. <p><strong>main.xml</strong></p><p></p><preclass="html"name="code"><?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical">
  6. <TextView
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:text="@string/hello"
  10. android:id="@+id/tv"
  11. />
  12. <SeekBar
  13. android:id="@+id/sb"
  14. android:layout_width="fill_parent"
  15. android:layout_height="wrap_content"
  16. />
  17. </LinearLayout></pre>
  18. <pre></pre>
  19. <preclass="html"name="code"><p><strong>SeekBarActivity.java</strong></p><p></p><preclass="java"name="code">packageorg.xiazdong;
  20. importandroid.app.Activity;
  21. importandroid.os.Bundle;
  22. importandroid.widget.SeekBar;
  23. importandroid.widget.SeekBar.OnSeekBarChangeListener;
  24. importandroid.widget.TextView;
  25. publicclassSeekBarActivityextendsActivity{
  26. privateTextViewtv;
  27. privateSeekBarsb;
  28. @Override
  29. publicvoidonCreate(BundlesavedInstanceState){
  30. super.onCreate(savedInstanceState);
  31. setContentView(R.layout.main);
  32. tv=(TextView)findViewById(R.id.tv);
  33. sb=(SeekBar)findViewById(R.id.sb);
  34. sb.setOnSeekBarChangeListener(newOnSeekBarChangeListener(){
  35. @Override
  36. publicvoidonProgressChanged(SeekBarseekBar,intprogress,
  37. booleanfromUser){
  38. tv.setText(progress+"");
  39. }
  40. @Override
  41. publicvoidonStartTrackingTouch(SeekBarseekBar){
  42. }
  43. @Override
  44. publicvoidonStopTrackingTouch(SeekBarseekBar){
  45. }
  46. });
  47. }
  48. }</pre>
  49. <pre></pre>
  50. <div><spanstyle="font-family:'MicrosoftYaHei'"></span></div>
  51. <div><spanstyle="font-family:'MicrosoftYaHei'"></span></div>
  52. <h2><aname="t22"></a><spanstyle="font-family:'MicrosoftYaHei'">11.ListView</span></h2>
  53. <div><spanstyle="font-family:'MicrosoftYaHei'">列表视图;</span></div>
  54. <h3><aname="t23"></a><spanstyle="font-family:'MicrosoftYaHei'">(1)使用ArrayAdapter实现普通列表</span></h3>
  55. <div><spanstyle="font-family:'MicrosoftYaHei'">ArrayAdapter是一个媒介,通过它可以把数组映射到ListView视图上。</span></div>
  56. <div>(1)newArrayAapter<String>(this,android.R.layout.simple_list_item_1,list);将list存放到ArrayAdapter中;</div>
  57. <div>(2)lv.setAdapter(adapter);为listView设置Adapter;</div>
  58. <div><spanstyle="font-family:'MicrosoftYaHei'"></span><preclass="java"name="code">packageorg.xiazdong;
  59. importjava.util.ArrayList;
  60. importandroid.app.Activity;
  61. importandroid.os.Bundle;
  62. importandroid.view.View;
  63. importandroid.widget.AdapterView;
  64. importandroid.widget.ArrayAdapter;
  65. importandroid.widget.ListView;
  66. importandroid.widget.Toast;
  67. importandroid.widget.AdapterView.OnItemClickListener;
  68. publicclassListViewActivityextendsActivityimplementsOnItemClickListener{
  69. ArrayList<String>list;
  70. @Override
  71. publicvoidonCreate(BundlesavedInstanceState){
  72. super.onCreate(savedInstanceState);
  73. list=newArrayList<String>();
  74. list.add("xiazdong-1");
  75. list.add("xiazdong-2");
  76. list.add("xiazdong-3");
  77. ArrayAdapteradapter=newArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);
  78. ListViewlv=newListView(this);
  79. lv.setAdapter(adapter);
  80. lv.setOnItemClickListener(this);
  81. this.setContentView(lv);
  82. }
  83. @Override
  84. publicvoidonItemClick(AdapterView<?>arg0,Viewarg1,intarg2,longarg3){
  85. Toast.makeText(this,list.get(arg2),Toast.LENGTH_SHORT).show();
  86. }
  87. }</pre><br>
  88. <h3><aname="t24"></a><spanstyle="font-family:'MicrosoftYaHei'">(2)自定义适配器BaseAdapter</span></h3>
  89. </div>
  90. <div><br>
  91. </div>
  92. <br>
  93. <h1><aname="t25"></a><spanstyle="font-family:'MicrosoftYaHei'">二、4种布局介绍</span></h1>
  94. <div><spanstyle="font-family:'MicrosoftYaHei'"><br>
  95. </span></div>
  96. <spanstyle="font-family:'MicrosoftYaHei'">AbsoluteLayout因为已被废除,因此不做介绍;<br>
  97. 只要存在界面,就会有布局的存在,就像Swing,虽然一个是桌面应用,一个是手机应用,但是他们都差不多。<br>
  98. </span>
  99. <h2style="font-family:monospace;white-space:pre"><aname="t26"></a><imgalt=""src="http://images.cnblogs.com/cnblogs_com/skynet/WindowsLiveWriter/Androidview_11A60/ViewGroup%E7%9A%84%E7%BB%A7%E6%89%BF_thumb.jpg"></h2>
  100. <br>
  101. 此处因为布局非常简单,所以就不用代码来讲解了。<br>
  102. <br>
  103. <br>
  104. <h2><aname="t27"></a><spanstyle="font-family:'MicrosoftYaHei'">1.LinearLayout</span></h2>
  105. <spanstyle="font-family:'MicrosoftYaHei'"><br>
  106. <br>
  107. 默认布局。组件的排列按照预先定义方向很有序的排列,类似于Swing中的FlowLayout;<br>
  108. 注意点:</span>
  109. <pre></pre>
  110. <pre></pre>
  111. <pre></pre>
  112. <pre></pre>
  113. <pre></pre>
  114. <pre></pre>
  115. <pre></pre>
  116. <pre></pre>
  117. </pre>
(1)可以在<LinearLayout>中添加android:orientation:vertical/horizontal ; (2)可以嵌套<LinearLayout>;

2.FrameLayout


每个组件都在左上角,如果多个组件一起出现,则会重叠;

3.RelativeLayout


每个组件定位都是按照与其他组件的上下、左右定位;
默认的定位为左上方;
(1)定位与组件的上下左右
android:layout_below="@id/.." android:layout_above="@id/" android:layout_toLeftOf="@id/" android:layout_toRightOf="@id/" (2)定位与组件的边缘对齐 android:layout_alignLeft="@id/" android:layout_alignRight="@id/" android:layout_alignTop="@id/" android:layout_alignBottom="@id/" (3)定位与父组件的边缘对齐 android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" (4)与整个屏幕的关系 android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_centerInParent="true"

4.TableLayout


类似于Swing中的GridLayout;
表格布局的每行用<TabRow>括起来; 在<TableLayout>中可以定义如下属性:
(1)android:shrinkColumns="1" 表明第2个控件如果里面的内容过多,会收缩,扩展到第二行,而不是延伸; (2)android:stretchColumns="2" 如果有空白,第3个控件填充;
在控件中设置:
(1)android:layout_column="2" 将此控件放在第3个位置; (2)android:layout_span="2" 此控件占据2个单元位置;

补充:


1.在Activity中根据id获得strings.xml和main.xml中的内容


getResources().getString(int id);
getResources().getDrawable(int id);


2.锁定横竖屏


因为在CTRL+F11时 会发生问题,因此可以再AndroidManifest.xml的Activity设置:android:screenOrientation=""

(1)portrait:竖屏;
(2)landscape:横屏;

3.可视化设置布局、控件

main.xml 如下所示:
Android 各种基础控件布局_第1张图片

多个Activity之间跳转


使用Intent进行多个页面的跳转; (1)Intent intent = new Intent(Context c,Class class); c表示当前界面,class表示要跳转到的界面的class; (2)intent.putExtra(String key,String value); //设置传输内容; (3)this.startActivity(intent); //开始跳转 (4)Intent intent = this.getIntent(); //获得传输来的intent (5)String value = intent.getStringExtra(String key); //获得数据

代码示例:


main.xml [html] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical">
  6. <TextView
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:text="第一个界面"/>
  10. <TextView
  11. android:id="@+id/tv1"
  12. android:layout_width="fill_parent"
  13. android:layout_height="wrap_content"
  14. android:text=""/>
  15. <EditText
  16. android:id="@+id/e1"
  17. android:layout_width="fill_parent"
  18. android:layout_height="wrap_content"
  19. android:hint="输入信息"
  20. />
  21. <Button
  22. android:id="@+id/b1"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:text="发送到第二个界面"
  26. />
  27. </LinearLayout>

mylayout.xml
[html] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical">
  6. <TextView
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:text="第二个界面"/>
  10. <TextView
  11. android:id="@+id/tv2"
  12. android:layout_width="fill_parent"
  13. android:layout_height="wrap_content"
  14. android:text=""/>
  15. <EditText
  16. android:id="@+id/e2"
  17. android:layout_width="fill_parent"
  18. android:layout_height="wrap_content"
  19. android:hint="输入信息"
  20. />
  21. <Button
  22. android:id="@+id/b2"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:text="发送到第一个界面"
  26. />
  27. </LinearLayout>

MultiActivityActivity.java
[java] view plain copy
  1. packageorg.xiazdong;
  2. importandroid.app.Activity;
  3. importandroid.content.Intent;
  4. importandroid.os.Bundle;
  5. importandroid.view.View;
  6. importandroid.view.View.OnClickListener;
  7. importandroid.widget.Button;
  8. importandroid.widget.EditText;
  9. importandroid.widget.TextView;
  10. publicclassMultiActivityActivityextendsActivityimplementsOnClickListener{
  11. privateButtonb1;
  12. privateEditTexte1;
  13. privateTextViewtv1;
  14. @Override
  15. publicvoidonCreate(BundlesavedInstanceState){
  16. super.onCreate(savedInstanceState);
  17. setContentView(R.layout.main);
  18. b1=(Button)findViewById(R.id.b1);
  19. e1=(EditText)findViewById(R.id.e1);
  20. tv1=(TextView)findViewById(R.id.tv1);
  21. Intenti=this.getIntent();
  22. if(i.getStringExtra("2")!=null){
  23. tv1.setText(i.getStringExtra("2"));
  24. }
  25. b1.setOnClickListener(this);
  26. }
  27. @Override
  28. publicvoidonClick(Viewv){
  29. Intentintent=newIntent(MultiActivityActivity.this,OtherActivity.class);
  30. intent.putExtra("1",e1.getText().toString());
  31. this.startActivity(intent);
  32. }
  33. }

OtherActivity.java

[java] view plain copy
  1. packageorg.xiazdong;
  2. importandroid.app.Activity;
  3. importandroid.content.DialogInterface;
  4. importandroid.content.Intent;
  5. importandroid.os.Bundle;
  6. importandroid.view.View;
  7. importandroid.view.View.OnClickListener;
  8. importandroid.widget.Button;
  9. importandroid.widget.EditText;
  10. importandroid.widget.TextView;
  11. publicclassOtherActivityextendsActivityimplementsOnClickListener{
  12. privateTextViewview;
  13. privateButtonb2;
  14. privateEditTexte2;
  15. privateTextViewtv2;
  16. @Override
  17. protectedvoidonCreate(BundlesavedInstanceState){
  18. super.onCreate(savedInstanceState);
  19. view=newTextView(this);
  20. setContentView(R.layout.mylayout);
  21. b2=(Button)findViewById(R.id.b2);
  22. e2=(EditText)findViewById(R.id.e2);
  23. tv2=(TextView)findViewById(R.id.tv2);
  24. Intenti=this.getIntent();
  25. if(i.getStringExtra("1")!=null){
  26. tv2.setText(i.getStringExtra("1"));
  27. }
  28. b2.setOnClickListener(this);
  29. }
  30. @Override
  31. publicvoidonClick(Viewv){
  32. Intentintent=newIntent(OtherActivity.this,MultiActivityActivity.class);
  33. intent.putExtra("2",e2.getText().toString());
  34. this.startActivity(intent);
  35. }
  36. }



[html] view plain copy
  1. <pre></pre>
  2. <pre></pre>
  3. <pre></pre>
  4. <pre></pre>
  5. <pre></pre>
  6. <pre></pre>

一、基本控件介绍


一般新建组件有两种方式:XML中定义和Java代码实现,一般XML中定义较为常用。

1.Button


按钮,在main.xml中定义如下:

[html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><Button
  2. <spanstyle="WHITE-SPACE:pre"></span>android:layout_width="wrap_content"<!--按钮宽度匹配文本的大小-->
  3. android:layout_height="wrap_content"<!--按钮高度匹配文本大小-->
  4. android:text="文本"<!--按钮的文本-->
  5. android:id="@+id/button1"<!--按钮的id-->
  6. ></Button></span>

Button的监听器:onClickListener;

需要实现方法:public void onClick(View v);v表示触发的控件,比如按钮

代码示例:实现点击按钮生成随机数;


ButtonActivity.java

[java] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';">packageorg.xiazdong;
  2. importjava.util.Random;
  3. importandroid.app.Activity;
  4. importandroid.app.AlertDialog;
  5. importandroid.app.AlertDialog.Builder;
  6. importandroid.os.Bundle;
  7. importandroid.view.View;
  8. importandroid.view.View.OnClickListener;
  9. importandroid.widget.Button;
  10. importandroid.widget.TextView;
  11. importandroid.widget.Toast;
  12. publicclassButtonActivityextendsActivityimplementsOnClickListener{//实现点击监听器
  13. privateButtonbutton;
  14. privateTextViewtv;
  15. @Override
  16. publicvoidonCreate(BundlesavedInstanceState){
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.main);
  19. button=(Button)findViewById(R.id.button1);//根据ID找组件
  20. tv=(TextView)findViewById(R.id.tv);
  21. button.setOnClickListener(this);//为button设置监听器
  22. }
  23. @Override
  24. publicvoidonClick(Viewview){
  25. Stringstr=newRandom().nextInt()+"";
  26. tv.setText(str);
  27. Toast.makeText(this,"点击了按钮!!",Toast.LENGTH_SHORT).show();//设置提示信息
  28. Builderbuilder=newAlertDialog.Builder(this);//创建对话框
  29. builder.setTitle("提示信息").setMessage("点击了按钮,随机数为:"+str).show();//设置对话框属性并显示
  30. }
  31. }</span>


main.xml

[html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical">
  6. <TextView
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:text=""
  10. android:id="@+id/tv"
  11. />
  12. <Button
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:text="点击生成随机数"
  16. android:id="@+id/button1"
  17. ></Button>
  18. </LinearLayout></span>

2.ImageButton


和Button的区别为背景可以自定义图片,在main.xml中定义如下:

[html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><ImageButton
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:id="@+id/ib1"
  5. android:background="@drawable/ic_launcher"/><!--设置按钮的背景为drawable文件夹下的ic_launcher图片--></span>


代码示例:实现点击图片按钮就切换图片;


main.xml [html] view plain copy
  1. <spanstyle="font-family:'MicrosoftYaHei';"><?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical">

更多相关文章

  1. android 展示单选列表对话框 builder.setSingleChoiceItems
  2. Android设置对话框去除黑边
  3. [置顶] Android中显示AlertDialog对话框
  4. Android官方入门文档[6]添加Action按钮
  5. Android 弹出对话框Dialog
  6. 界面编程之基本界面组件(5)ToggleButton(状态开关按钮)
  7. Android中创建对话框
  8. android Button 切换背景,实现动态按钮和按钮颜色渐变
  9. android点击按钮控制图片切换-kotlin

随机推荐

  1. Android: 浅论虚拟SD卡的实现
  2. Android按钮样式(dmytrodanylyk)使用
  3. android 打开软键盘 关闭软键盘
  4. 帧布局
  5. Android获得系统时间(24小时制)
  6. Android中常用的函数
  7. android canvas中的save()和restore()的
  8. 2011.07.12——— android Foreground se
  9. 深入理解zygote——1(代码源于GooGle)
  10. Android之如何使用junit