007.androidUI开发进阶(对话框) .
来源:互联网 发布:拐弯网络大电影 编辑:程序博客网 时间:2024/06/03 06:21
1.Dialog有四种,分别是AlertDialog,ProgressDialog,DatePickerDialog,TimePickerDialog
1.1AlertDialog
public class MainActivity extends Activity {private View view;private TextView tView;private EditText eText;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);view = layoutInflater.inflate(R.layout.cell, null);tView = (TextView) view.findViewById(R.id.tv2);eText = (EditText) view.findViewById(R.id.et1);new AlertDialog.Builder(this).setTitle("友情提示").setView(view).setMessage("确定退出?").setNegativeButton("取消", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubToast.makeText(MainActivity.this, "确定",Toast.LENGTH_SHORT).show();}}).setNeutralButton("中立", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubToast.makeText(MainActivity.this, "取消",Toast.LENGTH_SHORT).show();}}).setPositiveButton("确定", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubToast.makeText(MainActivity.this, eText.getText().toString(), Toast.LENGTH_SHORT).show();// tView.setText(eText.getText().toString());}}).show();}}
1.2ProgressDialog
ProgressDialog pgd = new ProgressDialog(this);pgd.setTitle("nihao");pgd.setMessage("hehe");//pgd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);pgd.setProgress(100);pgd.show();
1.3DatePickerDialog
DatePickerDialog datePickerDialog = new DatePickerDialog(this,new OnDateSetListener() {@Overridepublic void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {// TODO Auto-generated method stub}}, myear,mmouth,mday);datePickerDialog.show();
1.4 TimePickerDialog
于1.3相同的使用方式。
2.Menu有三种:分别是:optionsMenu,SubMenu,ContextMenu
2.1.OptionsMenu
public boolean onCreateOptionsMenu(Menu menu) {menu.add(menu.NONE,1,menu.NONE,"菜单1");menu.add(menu.NONE,2,menu.NONE,"菜单2");menu.add(menu.NONE,3,menu.NONE,"菜单3");menu.add(menu.NONE,4,menu.NONE,"菜单4");menu.add(menu.NONE,5,menu.NONE,"菜单5");return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {switch (item.getItemId()) {case 1:Toast.makeText(this,"1", Toast.LENGTH_SHORT).show();break;default:Toast.makeText(this,"其他", Toast.LENGTH_SHORT).show();break;}return super.onOptionsItemSelected(item);}
2.2.SubMenu
@Overridepublic boolean onCreateOptionsMenu(Menu menu) {menu.add(menu.NONE,1,menu.NONE,"菜单1");menu.add(menu.NONE,2,menu.NONE,"菜单2");menu.add(menu.NONE,3,menu.NONE,"菜单3");menu.add(menu.NONE,4,menu.NONE,"菜单4");menu.add(menu.NONE,5,menu.NONE,"菜单5");SubMenu subMenu = menu.addSubMenu(menu.NONE,6,menu.NONE,"菜单6"); subMenu.setHeaderTitle("你好");subMenu.setIcon(R.drawable.ic_launcher);subMenu.addSubMenu(menu.NONE,7,menu.NONE,"菜单7");return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {switch (item.getItemId()) {case 1:Toast.makeText(this,"1", Toast.LENGTH_SHORT).show();break;default:Toast.makeText(this,"其他", Toast.LENGTH_SHORT).show();break;}return super.onOptionsItemSelected(item);}
2.3ContextMenu
public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);TextView textView = (TextView) findViewById(R.id.tv1);registerForContextMenu(textView);}@Overridepublic void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {menu.add(menu.NONE,1,menu.NONE,"菜单1");menu.add(menu.NONE,2,menu.NONE,"菜单2");menu.add(menu.NONE,3,menu.NONE,"菜单3");menu.add(menu.NONE,4,menu.NONE,"菜单4");menu.add(menu.NONE,5,menu.NONE,"菜单5");super.onCreateContextMenu(menu, v, menuInfo);}@Overridepublic boolean onContextItemSelected(MenuItem item) {// TODO Auto-generated method stubswitch (item.getItemId()) {case 1:Toast.makeText(this,"1",Toast.LENGTH_SHORT).show();break;default:break;}return super.onContextItemSelected(item);}}
3.Notification
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); //声明Notification Notification notification = new Notification(); //设置notification的参数 notification.icon=R.drawable.ic_launcher; Intent intent = new Intent(this,MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this,0, intent,0); notification.setLatestEventInfo(this,"haha" ,"contentText",pendingIntent); notificationManager.notify(10,notification);
4.TabHost
TabHost tabHost = getTabHost();LayoutInflater.from(this).inflate(R.layout.activity_main,tabHost.getTabContentView(), true);Intent intent = new Intent(MainActivity.this, SeocndActivity.class);tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("搜索").setContent(intent));tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("搜索").setContent(intent));tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("搜索").setContent(R.id.l1));
- 007.androidUI开发进阶(对话框) .
- androidUI-对话框
- AndroidUI开发初印象
- AndroidUI 开发常用颜色
- androidUI开发中的规范
- bootStrap 弹出对话框进阶
- AngularJS进阶(三十一)AngularJS项目开发技巧之获取模态对话框中的组件ID
- androidUI开发之-优化你的布局层次结构
- 【Android 应用开发】AndroidUI设计 之 图片浏览器
- androidUI开发之自定义Android标题栏TitleBar布局
- Android 对话框进阶(自定义)
- androidUI TableLayout
- androidUI ListView
- AndroidUI组件
- AndroidUI优化
- AndroidUI设计
- AndroidUI设计
- AndroidUI ToolBar
- 修改MySQL 5.5的max_allowed_packet属性的方法
- SystemUi-Notification 随手指动态显示分析
- ajax提交返回boolean类型
- ORA-00918: column ambiguously defined
- wikioi p1017 乘积最大
- 007.androidUI开发进阶(对话框) .
- deep copy
- tomcat下的work文件夹
- 打印两点间的所有路径
- 如何看懂man page
- wikioi p1039 数的划分
- 微软安全新闻聚焦-双周刊第三十七期
- CF 39E What Has Dirichlet Got to Do with That? (博弈)
- upstream timed out (110: Connection timed out) while reading response header from upstream 问题解决