




已阅读5页,还剩17页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
常用系统控件界面大合集今天我用自己写的一个Demo 和大家详细介绍一个Android开发中遇到的一些常用系统控件的使用技巧。2011-9-2 19:37:07 上传下载附件 (43.67 KB) 1.文本框TextView TextView的作用是用来显示一个文本框,下面我用两种方式为大家呈现TextView, 第一种是通过xml布局文件呈现 ,第二种是通过代码来呈现,由此可见Android 的界面非常灵活。2011-9-2 19:37:12 上传下载附件 (23.83 KB) 1. public class TextViewActivity extends Activity 2. Override3. protected void onCreate(Bundle savedInstanceState) 4. setContentView(R.layout.textview);5. 6. LinearLayout ll = (LinearLayout) findViewById(R.id.textviewll);7. TextView textView = new TextView(this);8. /设置显示文字9. textView.setText(从代码中添加一个TextView);10. /设置显示颜色11. textView.setTextColor(Color.WHITE);12. /设置显示字体大小13. textView.setTextSize(18);14. /设置显示背景颜色15. textView.setBackgroundColor(Color.BLUE);16. /设置锚点位置17. textView.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL);18. /把这个view加入到布局当中19. ll.addView(textView);20. 21. super.onCreate(savedInstanceState);22. 23. 复制代码1. 2. 6. 15. 复制代码2.网页框WebViewWebView可以实现 类似web的网页 的系统控件最主要的是可以使用html代码,如访问网页等。2011-9-2 19:37:14 上传下载附件 (23.73 KB) 2011-9-2 19:37:30 上传下载附件 (55.5 KB) 1. public class WebViewActivity extends Activity 2. WebView webView = null;3. static final String MIME_TYPE = text/html;4. static final String ENCODING = utf-8;5. 6. 7. Override8. protected void onCreate(Bundle savedInstanceState) 9. setContentView(R.layout.webview);10. 11. webView = (WebView) findViewById(R.id.webview);12. webView.loadDataWithBaseURL(null,欢迎访问雨松MOMO的博客, MIME_TYPE, ENCODING, null);13. super.onCreate(savedInstanceState);14. 15. 复制代码1. 2. 6. 14. 17. 复制代码3.Menu菜单 Menu菜单在android系统控件中真的很具有特色 点击以后会悬浮出一个菜单在次点击菜单则会消失,今天我只是简单的介绍一下系统的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. Override4. protected void onCreate(Bundle savedInstanceState) 5. setContentView(R.layout.menuview);6. super.onCreate(savedInstanceState);7. 8.9. Override10. public boolean onCreateOptionsMenu(Menu menu) 11. menu.add(0, 0, Menu.NONE, 菜单1).setIcon(R.drawable.icon);12. menu.add(0, 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, 菜单6).setIcon(R.drawable.icon);17. return super.onCreateOptionsMenu(menu);18. 19.20. Override21. public boolean onOptionsItemSelected(MenuItem item) 22. Dialog(item.getItemId();23. return super.onOptionsItemSelected(item);24. 25.26. private void Dialog(int message) 27. new AlertDialog.Builder(this).setMessage(28. 您单击第【 + message + 】项Menu菜单项.).show();29. 30. 复制代码1. 2. 5. 13. 复制代码4.按钮Button第一个是绘制系统字的button, 第二个是带图片的button 。2011-9-2 19:37:55 上传下载附件 (30.13 KB) 1. public class ButtonActivity extends Activity 2.3. Context mContext = null;4. Override5. protected void onCreate(Bundle savedInstanceState) 6. setContentView(R.layout.buttonview);7. mContext = 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. button0.setOnClickListener(new OnClickListener() 19. 20. Override21. public void onClick(View arg0) 22. Toast.makeText(ButtonActivity.this, 您点击了这是一个按钮, Toast.LENGTH_LONG).show();23. 24. 25. );26. 27. /带图片的按钮28. ImageButton button1 = (ImageButton)findViewById(R.id.buttonview1);29. /设置按钮监听 点击事件30. button1.setOnClickListener(new OnClickListener() 31. 32. Override33. public void onClick(View arg0) 34. Toast.makeText(ButtonActivity.this, 您点击了一个带图片的按钮, Toast.LENGTH_LONG).show();35. 36. 37. );38. super.onCreate(savedInstanceState);39. 40. 复制代码1. 2. 5. 13. 19. 25. 复制代码5.编辑框EditView编辑框在实际开发中用到的非常普遍 比如登录 输入账号 密码 等等。2011-9-2 19:37:58 上传下载附件 (32.99 KB) 1. public class EditTextActivity extends Activity 2.3. Context mContext = null;4. Override5. protected void onCreate(Bundle savedInstanceState) 6. setContentView(R.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 button = (Button)findViewById(R.id.editbutton0);15. 16. button.setOnClickListener(new OnClickListener() 17. 18. Override19. public void onClick(View arg0) 20. String username = editText0.getText().toString();21. 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. 2. 5. 13. 20. 21. 28. 34. 复制代码6.单项选择 使用RadioGroup 包住若干个RadioButton 来实现单项选择。监听每一个RadioGroup 就可以知道那个单选组中的第一个ID被按下。2011-9-2 19:38:13 上传下载附件 (32.81 KB) 1. public class RadioActivity extends Activity 2.3. Context mContext = null;4. Override5. protected void onCreate(Bundle savedInstanceState) 6. setContentView(R.layout.radioview);7. mContext = this;8. /单选组(只有在一个组中的按钮可以单选)9. RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radion0);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)findViewById(R.id.radionButton2);15. 16. radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() 17. 18. Override19. public void onCheckedChanged(RadioGroup arg0, int checkID) 20. if(radioButton0.getId() = checkID) 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_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 radioGroup0 = (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 RadioButton radioButton5 = (RadioButton)findViewById(R.id.radionButton5);36. 37. radioGroup0.setOnCheckedChangeListener(new OnCheckedChangeListener() 38. 39. Override40. public void onCheckedChanged(RadioGroup arg0, int checkID) 41. 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, 您选中了第二组 + 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. );50. super.onCreate(savedInstanceState);51. 52. 复制代码1. 2. 5. 13. 17. 23. 29. 35. 36.37. 45. 49. 55. 61. 67. 68. 复制代码7.多项选择使用系统控件Checkbox监听每一个checkbox 的点击事件就可以确定那几个选项被选择了。2011-9-2 19:36:44 上传下载附件 (28.52 KB) 1. public class CheckboxActivity extends Activity 2.3. /用来储存选中的内容4. ArrayList item = new ArrayList();5. 6. Override7. protected void onCreate(Bundle savedInstanceState) 8. setContentView(R.layout.checkboxview);9. 10. CheckBox checkbox0 = (CheckBox)findViewById(R.id.checkboxview0); 11. CheckBox checkbox1 = (CheckBox)findViewById(R.id.checkboxview1); 12. CheckBox checkbox2 = (CheckBox)findViewById(R.id.checkboxview2); 13. CheckBox checkbox3 = (CheckBox)findViewById(R.id.checkboxview3); 14. Button button = (Button)findViewById(R.id.checkboxbutton); 15. /对checkb
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 初三数学二次函数章节测试试卷及答案
- 初三数学二次函数难点题型试卷及答案
- 企业安全环保考试题库及答案解析
- 汕头大学护理考试题库及答案解析
- 驾驶员安全知识考试题库及答案解析
- 2025年国家开放大学(电大)《医学影像学》期末考试备考试题及答案解析
- 安全培训师傅点评课件
- 2025年氧气吸入考试试题及答案
- 2025年结核知识培训试题及答案
- 基金从业资格考试变更及答案解析
- 2025年辅警考试真题及答案
- 2025-2026学年统编版五年级上册语文第二单元过关试卷附答案(三套)
- 2025年农村土地租赁协议(合同样本)
- 2025年固态变压器(SST)行业研究报告及未来发展趋势预测
- 海上安全培训课课件
- 神经外科重症管理临床指南
- 少年读史记课件
- 铁路客运防寒过冬课件
- 2025至2030中国生物保健品行业项目调研及市场前景预测评估报告
- 急性肺栓塞诊断和治疗指南(2025版)解读
- 2025年三力测试题试题及答案
评论
0/150
提交评论