11、"wrap_content"
8. android:textColor="#000000"
9. android:textSize="18dip"
10. android:background="#00FF00"
11. android:text="网页框WebView测试"
12. android:gravity="center_ver
12、tical|center_horizontal"
13. />
14.
17.
复制代码
3.Menu菜单
Menu菜单在android系统控件中真的很具有特
13、色 点击以后会悬浮出一个菜单在次点击菜单则会消失,今天我只是简单的介绍一下系统的Menu菜单, 其实Menu菜单可以做出非常好看的效果,比如半透明 自定义按钮图片等等,后面我会详细的介绍menu菜单。
2011-9-2 19:37:33 上传
下载附件 (32.99 KB)
2011-9-2 19:37:47 上传
下载附件 (21.67 KB)
1. public class MenuActivity extends Activity {
2.
3. @Override
4. protected void onCreate(Bundle sav
14、edInstanceState) {
5. setContentView(R.layout.menuview);
6. super.onCreate(savedInstanceState);
7. }
8.
9. @Override
10. public boolean onCreateOptionsMenu(Menu menu) {
11. menu.add(0, 0, Menu.NONE, "菜单1").setIcon(R.drawable.icon);
12. menu.add(0,
15、1, Menu.NONE, "菜单2").setIcon(R.drawable.icon);
13. menu.add(0, 2, Menu.NONE, "菜单3").setIcon(R.drawable.icon);
14. menu.add(0, 3, Menu.NONE, "菜单4").setIcon(R.drawable.icon);
15. menu.add(0, 4, Menu.NONE, "菜单5").setIcon(R.drawable.icon);
16. menu.add(0, 5, Menu.NONE
16、 "菜单6").setIcon(R.drawable.icon);
17. return super.onCreateOptionsMenu(menu);
18. }
19.
20. @Override
21. public boolean onOptionsItemSelected(MenuItem item) {
22. Dialog(item.getItemId());
23. return super.onOptionsItemSelected(item);
24. }
25.
26.
17、 private void Dialog(int message) {
27. new AlertDialog.Builder(this).setMessage(
28. "您单击第【" + message + "】项Menu菜单项.").show();
29. }
30. }
复制代码
1.
2. 18、" android:layout_width="fill_parent"
4. android:layout_height="fill_parent">
5. 19、ndroid:textSize="18dip"
9. android:background="#00FF00"
10. android:text="Menu菜单测试"
11. android:gravity="center_vertical|center_horizontal"
12. />
13.
复制代码
4.按钮Button
第一个是绘制系统字的butt
20、on, 第二个是带图片的button 。
2011-9-2 19:37:55 上传
下载附件 (30.13 KB)
1. public class ButtonActivity extends Activity {
2.
3. Context mContext = null;
4. @Override
5. protected void onCreate(Bundle savedInstanceState) {
6. setContentView(R.layout.buttonview);
7. mContext
21、 this;
8.
9. //普通按钮
10. Button button0 = (Button)findViewById(R.id.buttonview0);
11.
12. //设置按钮文字颜色
13. button0.setTextColor(Color.BLUE);
14. //设置按钮文字大小
15. button0.setTextSize(30);
16.
17. //设置按钮监听 点击事件
18.
22、 button0.setOnClickListener(new OnClickListener() {
19.
20. @Override
21. public void onClick(View arg0) {
22. Toast.makeText(ButtonActivity.this, "您点击了‘这是一个按钮’", Toast.LENGTH_LONG).show();
23.
24. }
25.
23、 });
26.
27. //带图片的按钮
28. ImageButton button1 = (ImageButton)findViewById(R.id.buttonview1);
29. //设置按钮监听 点击事件
30. button1.setOnClickListener(new OnClickListener() {
31.
32. @Override
33. public void onClick(View
24、arg0) {
34. Toast.makeText(ButtonActivity.this, "您点击了一个带图片的按钮", Toast.LENGTH_LONG).show();
35.
36. }
37. });
38. super.onCreate(savedInstanceState);
39. }
40. }
复制代码
1.
2. 25、xmlns:android="
3. android:orientation="vertical" android:layout_width="fill_parent"
4. android:layout_height="fill_parent">
5. 26、droid:textColor="#000000"
8. android:textSize="18dip"
9. android:background="#00FF00"
10. android:text="Button按钮测试"
11. android:gravity="center_vertical|center_horizontal"
12.
27、/>
13.
19. 28、eButton
20. android:id="@+id/buttonview1"
21. android:layout_width="fill_parent"
22. android:layout_height="wrap_content"
23. android:src="@drawable/icon"
24. />
25.
29、>
复制代码
5.编辑框EditView
编辑框在实际开发中用到的非常普遍 比如登录 输入账号 密码 等等。
2011-9-2 19:37:58 上传
下载附件 (32.99 KB)
1. public class EditTextActivity extends Activity {
2.
3. Context mContext = null;
4. @Override
5. protected void onCreate(Bundle savedInstanceState) {
6. setContentView(R.
30、layout.editview);
7. mContext = this;
8. //帐号
9. final EditText editText0 = (EditText)findViewById(R.id.editview0);
10. //密码
11. final EditText editText1 = (EditText)findViewById(R.id.editview1);
12.
13. //确认按钮
14. Button butto
31、n = (Button)findViewById(R.id.editbutton0);
15.
16. button.setOnClickListener(new OnClickListener() {
17.
18. @Override
19. public void onClick(View arg0) {
20. String username = editText0.getText().toString();
21.
32、 String password = editText1.getText().toString();
22. Toast.makeText(EditTextActivity.this, "用户名:"+username +"密码:"+ password, Toast.LENGTH_LONG).show();
23. }
24. });
25. super.onCreate(savedInstanceState);
26. }
27. }
复制代码
1.
33、sion="1.0" encoding="utf-8"?>
2.
5. 34、"wrap_content"
7. android:textColor="#000000"
8. android:textSize="18dip"
9. android:background="#00FF00"
10. android:text="EditText编辑框测试"
11. android:gravity="center_vert
35、ical|center_horizontal"
12. />
13. 36、 android:phoneNumber="true"
19. />
20.
21. 37、5. android:hint="请输入密码"
26. android:password="true"
27. />
28.
复制代码
6.单项选择
使用RadioGroup 包住若干个RadioButton 来实现单项选择。监听每一个RadioGroup 就可以知道那个单选组中的第一个ID被按下。
2011-9-2 19:38:13 上传
下载附件 (32.81 KB)
1. public class RadioActivity extends Activity
39、 {
2.
3. Context mContext = null;
4. @Override
5. protected void onCreate(Bundle savedInstanceState) {
6. setContentView(R.layout.radioview);
7. mContext = this;
8. //单选组(只有在一个组中的按钮可以单选)
9. RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radi
40、on0);
10.
11. //单选按钮(第一组)
12. final RadioButton radioButton0 = (RadioButton)findViewById(R.id.radionButton0);
13. final RadioButton radioButton1 = (RadioButton)findViewById(R.id.radionButton1);
14. final RadioButton radioButton2 = (RadioButton)findViewBy
41、Id(R.id.radionButton2);
15.
16. radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
17.
18. @Override
19. public void onCheckedChanged(RadioGroup arg0, int checkID) {
20. if(radioButton0.getId() == checkID)
42、 {
21. Toast.makeText(RadioActivity.this, "您选中了第一组" + radioButton0.getText(), Toast.LENGTH_LONG).show();
22. }else if(radioButton1.getId() == checkID) {
23. Toast.makeText(RadioActivity.this, "您选中了第一组" + radioButton1.getText(), Toast.LENGTH_
43、LONG).show();
24. }else if(radioButton2.getId() == checkID) {
25. Toast.makeText(RadioActivity.this, "您选中了第一组" + radioButton2.getText(), Toast.LENGTH_LONG).show();
26. }
27. }
28. });
29.
30. RadioGroup r
44、adioGroup0 = (RadioGroup)findViewById(R.id.radion1);
31.
32. //单选按钮(第二组)
33. final RadioButton radioButton3 = (RadioButton)findViewById(R.id.radionButton3);
34. final RadioButton radioButton4 = (RadioButton)findViewById(R.id.radionButton4);
35. final Rad
45、ioButton radioButton5 = (RadioButton)findViewById(R.id.radionButton5);
36.
37. radioGroup0.setOnCheckedChangeListener(new OnCheckedChangeListener() {
38.
39. @Override
40. public void onCheckedChanged(RadioGroup arg0, int checkID) {
41.
46、 if(radioButton3.getId() == checkID) {
42. Toast.makeText(RadioActivity.this, "您选中了第二组" + radioButton3.getText(), Toast.LENGTH_LONG).show();
43. }else if(radioButton4.getId() == checkID) {
44. Toast.makeText(RadioActivity.this, "
47、您选中了第二组" + radioButton4.getText(), Toast.LENGTH_LONG).show();
45. }else if(radioButton5.getId() == checkID) {
46. Toast.makeText(RadioActivity.this, "您选中了第二组" + radioButton5.getText(), Toast.LENGTH_LONG).show();
47. }
48. }
49.
48、 });
50. super.onCreate(savedInstanceState);
51. }
52. }
复制代码
1.
2.
5.