Android UI(二)
来源:互联网 发布:淘宝代销怎么设置运费 编辑:程序博客网 时间:2024/06/16 00:26
一、UI Controls
UI Controls是一组与用户输入有关的组件,属于非容器View。
下面主要介绍基本组件如下:
1) Buttons
a)Button
b)ImageButton
c)Switch(开关): checked
d)CheckBox(复选框): checked
e)RadioButton(单选框):RadioGroup(线性布局的子类)
2)TextFields (文本域)
a)EditText(编辑框)
设定光标位置为末尾
<span style="white-space:pre"></span>et.setSelection(edit03.getText().length());
b)AutoCompleteTextView(自动完成编辑框)
//自动完成ato=(AutoCompleteTextView) findViewById(R.id.atoTextView);//设置何时出现提示字符(1表示输入一个字符时,默认是两个字符)ato.setThreshold(1);//关联适配器ato.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,new String[]{"AA1","AA2","CC1","C2","C3","CC4"}));
c)SearchView(查询框,内置了一个AutoCompleteText)
3)Bars(条)
a)ProgressBar (进度条)
b)SeekBar(拖动条)
c)RatingBar(评价条)
二、UI Components
UI Components是用于呈现view的组件
常用类型有:
1) Menu (菜单)
①选项菜单(Option Menu)
②上下文菜单(Context Menu)
③弹出式菜单(Popup Menu)
④子菜单
2) ActionBar(动作栏)
android3.0推出的一个新的对象,
此对象最主要的目的是在标题栏更好的为用户呈现一些view组件,并实现与用户的交互,可以呈现Menu对象。
*在配置ActionBar之前要获取当前ActionBar,采用方法getActionBar();在获取ActionBar之前,要确认选择的Activity主题是有ActionBar的。
//1.获得ActionBarActionBar ab = getActionBar();//2.设置ActionBar//2.1设置显示Action向左的箭头:并且设置homeButton//ab.setDisplayHomeAsUpEnabled(true);//2.2设置homeButton可点击ab.setHomeButtonEnabled(true);//2.3隐藏标题//ab.setDisplayShowTitleEnabled(false);////2.4隐藏home图标//ab.setDisplayShowHomeEnabled(false);//3.设置actionBar的导航模式//3.1设置tab导航ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);//3.2添加tab导航ab.addTab(ab.newTab().setText("text01").setTabListener(new TabListener() {<span style="white-space:pre"></span>@Override<span style="white-space:pre"></span>public void onTabUnselected(Tab tab, FragmentTransaction ft) {<span style="white-space:pre"></span>// TODO Auto-generated method stub<span style="white-space:pre"></span>}@Overridepublic void onTabSelected(Tab tab, FragmentTransaction ft) {// TODO Auto-generated method stub}@Overridepublic void onTabReselected(Tab tab, FragmentTransaction ft) {// TODO Auto-generated method stub}}));
3) Dialog(对话框)
Dialog是一个浮动窗口
主要有如下三种:
a) AlertDialog(提示对话框)(通过Builder对象来创建)
具体实现:
AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setIcon(R.drawable.ic_launcher);builder.setTitle("title");builder.setMessage("message");AlertDialog ad = builder.create();ad.show();
b) DatePickerDialog(日期对话框)
c) ProgressDialog(进度对话框)
4) Notification(通知)
用于手机状态栏显示的对象
一般应用于Android的服务端(service),可以在service端创建,并发送,然后显示在状态栏。
Notification noti = new Notification.Builder(this).setSmallIcon(R.drawable.ic_launcher)//必须写一图标.setContentTitle("Title").setContentText("text").setTicker("here's a message for u")//引爆消息.build();//发送通知NotificationManager nManager;nManager = (NotificationManager) //系统服务getSystemService(Context.NOTIFICATION_SERVICE);nManager.notify(0, noti);
5) Toast(通知)
创建方式:1.构造方法2.静态方式makeText
常用方法:makeText(…),show()
Toast t = new Toast(this);t.setGravity(Gravity.CENTER, 0, 0);TextView tv = new TextView(this);tv.setText(R.string.hello_world);t.setView(tv);//不能像makeText直接放文本进去,需放一个view进去t.setDuration(1);t.show();
6)Setting(设置)
- Android UI控件二
- Android UI(二)
- android UI小结(二)
- Android UI学习(二)
- Android UI学习(二)
- Android UI绘制原理(二)
- Android UI绘制流程(二)
- Android优化UI(二)
- android UI线程与非UI线程交互(二)
- Android UI组件开源实例(二)
- Android TV UI 设计指南 《二》
- Android UI组件开源实例(二)
- 转android的UI设计二
- 【Android基础】(8)UI控件(二)
- Android PullToRefresh 分析之二、UI结构
- Android UI布局与控件(二)
- Android UI性能优化(二)
- Android UI控件学习笔记(二)
- PAT-基础编程题-5-38 数列求和-加强版
- Unity之快捷键组合
- Kali进行web渗透笔记(六)
- 代码训练营—File,删除一个带内容的目录
- Kali进行web渗透笔记(七)
- Android UI(二)
- 正则表达式使用
- Chromium网页Pending Layer Tree激活为Active Layer Tree的过程分析
- 我的第一个公众号
- Kali进行web渗透笔记(八)
- Kali进行web渗透笔记(九)
- 第一篇博文
- Kali进行web渗透笔记(十)
- Kali进行web渗透笔记(十一)