- 浏览: 5778638 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (890)
- WindowsPhone (0)
- android (88)
- android快速迭代 (17)
- android基础 (34)
- android进阶 (172)
- android高级 (0)
- android拾遗 (85)
- android动画&效果 (68)
- Material Design (13)
- LUA (5)
- j2me (32)
- jQuery (39)
- spring (26)
- hibernate (20)
- struts (26)
- tomcat (9)
- javascript+css+html (62)
- jsp+servlet+javabean (14)
- java (37)
- velocity+FCKeditor (13)
- linux+批处理 (9)
- mysql (19)
- MyEclipse (9)
- ajax (7)
- wap (8)
- j2ee+apache (24)
- 其他 (13)
- phonegap (35)
最新评论
-
Memories_NC:
本地lua脚本终于执行成功了,虽然不是通过redis
java中调用lua脚本语言1 -
ZHOU452840622:
大神://处理返回的接收状态 这个好像没有监听到 遇 ...
android 发送短信的两种方式 -
PXY:
拦截部分地址,怎么写的for(int i=0;i<lis ...
判断是否登录的拦截器SessionFilter -
maotou1988:
Android控件之带清空按钮(功能)的AutoComplet ...
自定义AutoCompleteTextView -
yangmaolinpl:
希望有表例子更好。。。,不过也看明白了。
浅谈onInterceptTouchEvent、onTouchEvent与onTouch
setFocusable() 设置view接受焦点的资格
isFocusable() view是否具有接受焦点的资格
setFocusInTouchMode() 对应在触摸模式下,设置是否有焦点来响应点触的资格
isFocusableInTouchMode() 对应在触摸模式下,view是否具有焦点的资格
强制view焦点获取,注意:这些方法都不会触发事件(onTouch,onClick等),想要触发onClick事件请调用view.performClick()
requestFocus() ------ view
requestFocus(int direction)当用户在某个界面聚集焦点,参数为下面的4个
requestFocusFromTouch() 触摸模式下
......
requestChildFocus (View child, View focused) ------viewGroup
1 父元素调用此方法
2 child 将要获取焦点的子元素
3 focused 现在拥有焦点的子元素
一般也可以通过 配置文件设置
View.FOCUS_LEFT Move focus to the left
View.FOCUS_UP Move focus up
View.FOCUS_RIGHT Move focus to the right
View.FOCUS_DOWN Move focus down
代码设置实现 其实都是通过这些设置的
isInTouchMode() 触摸模式
-------------------------------------------------------------------------------
下面的例子主要使用了requestFocus()方法使焦点在各个控件之间切换。
看下图:
最上面的弹出框是个PopupWindow,需要依次输入4个密码,为了方便快捷,当上一个文本框输入值之后,焦点自动切换到下一个文本框,当输入到最后一个文本框后,PopupWindow自动关闭,并返回4个文本框中的值,放在String[]数组中。
看代码:
在Activity中的用法就简单了:
如果弹出PasswordPopupWindow后没有弹出输入法,则强制显示输入法:
PasswordPopupWindow的布局文件popup_window_password.xml如下:
动画文件:
anim_top_in.xml
anim_top_out.xml
isFocusable() view是否具有接受焦点的资格
setFocusInTouchMode() 对应在触摸模式下,设置是否有焦点来响应点触的资格
isFocusableInTouchMode() 对应在触摸模式下,view是否具有焦点的资格
强制view焦点获取,注意:这些方法都不会触发事件(onTouch,onClick等),想要触发onClick事件请调用view.performClick()
requestFocus() ------ view
requestFocus(int direction)当用户在某个界面聚集焦点,参数为下面的4个
requestFocusFromTouch() 触摸模式下
......
requestChildFocus (View child, View focused) ------viewGroup
1 父元素调用此方法
2 child 将要获取焦点的子元素
3 focused 现在拥有焦点的子元素
一般也可以通过 配置文件设置
View.FOCUS_LEFT Move focus to the left
View.FOCUS_UP Move focus up
View.FOCUS_RIGHT Move focus to the right
View.FOCUS_DOWN Move focus down
代码设置实现 其实都是通过这些设置的
isInTouchMode() 触摸模式
-------------------------------------------------------------------------------
下面的例子主要使用了requestFocus()方法使焦点在各个控件之间切换。
看下图:
最上面的弹出框是个PopupWindow,需要依次输入4个密码,为了方便快捷,当上一个文本框输入值之后,焦点自动切换到下一个文本框,当输入到最后一个文本框后,PopupWindow自动关闭,并返回4个文本框中的值,放在String[]数组中。
看代码:
package com.reyo.view; import android.content.Context; import android.graphics.drawable.BitmapDrawable; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.widget.EditText; import android.widget.ImageButton; import android.widget.LinearLayout.LayoutParams; import android.widget.PopupWindow; import com.reyo.merchant2.R; public class PasswordPopupWindow extends PopupWindow { private Context context; private EditText[] texts; private ImageButton btn_close; public PasswordPopupWindow(Context context, View view) { super(view, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, true); this.context = context; this.setBackgroundDrawable(new BitmapDrawable());// 响应返回键,响应触摸周边消失 this.setAnimationStyle(R.style.PopupAnimationFromTop); this.setInputMethodMode(PopupWindow.INPUT_METHOD_FROM_FOCUSABLE); texts = new EditText[4]; texts[0] = (EditText) view.findViewById(R.id.et_0); texts[1] = (EditText) view.findViewById(R.id.et_1); texts[2] = (EditText) view.findViewById(R.id.et_2); texts[3] = (EditText) view.findViewById(R.id.et_3); for (int i = 0; i < texts.length; i++) { final int curIndex = i; texts[i].addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub int nextIndex = curIndex + 1; //当输入到最后一个EditText时关闭PopupWindow if (nextIndex >= texts.length) { dismiss(); return; } texts[nextIndex].requestFocus(); } }); } btn_close = (ImageButton) view.findViewById(R.id.btn_close); btn_close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub dismiss(); } }); this.setOnDismissListener(onDismissListener); } private OnDismissListener onDismissListener = new OnDismissListener() { public void onDismiss() { // TODO Auto-generated method stub if (onCompleteListener != null) { String[] text = new String[texts.length]; for (int i = 0; i < texts.length; i++) { text[i] = texts[i].getText().toString(); } onCompleteListener.onComplete(text); } // 清空&归位 for (int i = 0; i < texts.length; i++) { texts[i].setText(""); } texts[0].requestFocus(); } }; private OnCompleteListener onCompleteListener; public void setOnCompleteListener(OnCompleteListener onCompleteListener) { this.onCompleteListener = onCompleteListener; } public interface OnCompleteListener { public void onComplete(String[] texts); } }
在Activity中的用法就简单了:
private PasswordPopupWindow popupWindow; if (popupWindow == null) { LayoutInflater mLayoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View popup_view = mLayoutInflater.inflate(R.layout.popup_window_password,null); popupWindow = new PasswordPopupWindow(context, popup_view); // popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_FROM_FOCUSABLE); popupWindow.showAtLocation(container, Gravity.TOP, 0, 0); popupWindow.setOnCompleteListener(new PasswordPopupWindow.OnCompleteListener() { @Override public void onComplete(String[] texts) { // TODO Auto-generated method stub StringBuffer sb = new StringBuffer(); for (int i = 0; i < texts.length; i++) { sb.append(texts[i]); } String p=sb.toString(); if(p.length()==texts.length){ //doSomethingYouWant(); } } }); } else { if (!popupWindow.isShowing()) { popupWindow.showAtLocation(container, Gravity.TOP, 0, 0); } } // 强制显示输入法 toggleSoftInput(context);
如果弹出PasswordPopupWindow后没有弹出输入法,则强制显示输入法:
/** * 如果输入法打开则关闭,如果没打开则打开 * * @param context */ protected void toggleSoftInput(Context context) { InputMethodManager inputMethodManager = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); }
PasswordPopupWindow的布局文件popup_window_password.xml如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical" android:orientation="vertical" android:background="@color/gray1" > <ImageButton android:id="@+id/btn_close" android:layout_width="60dp" android:layout_height="60dp" android:background="@android:color/transparent" android:src="@drawable/bg_btn_close" android:scaleType="center" android:layout_gravity="top|right" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" > <EditText android:id="@+id/et_0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textPassword" android:singleLine="true" android:minWidth="60dp" android:minHeight="60dp" android:maxLength="1" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:gravity="center" android:textSize="@dimen/font_xxxbig" /> <EditText android:id="@+id/et_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textPassword" android:singleLine="true" android:minWidth="60dp" android:minHeight="60dp" android:maxLength="1" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:gravity="center" android:textSize="@dimen/font_xxxbig" /> <EditText android:id="@+id/et_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textPassword" android:singleLine="true" android:minWidth="60dp" android:minHeight="60dp" android:maxLength="1" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:gravity="center" android:textSize="@dimen/font_xxxbig" /> <EditText android:id="@+id/et_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textPassword" android:singleLine="true" android:minWidth="60dp" android:minHeight="60dp" android:maxLength="1" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:gravity="center" android:textSize="@dimen/font_xxxbig" /> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="请输入操作密码(该操作由服务员完成)" android:textColor="@color/white" android:textSize="@dimen/font_middle" android:singleLine="true" android:layout_margin="20dp" android:layout_gravity="center_horizontal" /> </LinearLayout>
动画文件:
<style name="PopupAnimationFromTop" parent="android:Animation" mce_bogus="1" > <item name="android:windowEnterAnimation">@anim/anim_top_in</item> <item name="android:windowExitAnimation">@anim/anim_top_out</item> </style>
anim_top_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="-100%p" android:toYDelta="0" android:duration="200" android:fillAfter="true" android:interpolator="@android:anim/bounce_interpolator" /> </set>
anim_top_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="0" android:toYDelta="-100%p" android:duration="200" android:fillAfter="true" android:interpolator="@android:anim/bounce_interpolator" /> </set>
发表评论
-
某些android手机获取不到IMEI问题
2018-08-21 14:17 7496某些山寨机可能拿不到IMEI 如果非要IMEI可以模拟一个 ... -
APK安装成功后点击"打开"再按Home键应用会重启的问题
2018-08-21 14:13 2714安装系统SD卡里面的apk或者原有的程序更新版本的时候, ... -
使用volley链接Https地址时报SSLHandshakeException
2018-08-21 14:06 2035在真实设备上出现以下错误 ︰ Volley error: ... -
PhotoView+Viewpager双指缩放的时候出现pointerIndex out of range问题
2017-07-10 14:30 4188PhotoView+Viewpager开发图集效果的时候,在某 ... -
Android6.0权限封装
2017-04-01 12:04 1527简介 Android6.0中对权限分为了一般权限和危险权限。 ... -
实现点击 WebView 中的图片,调用原生控件展示图片
2017-04-01 11:14 2748现在有很多时候,我们的 App 都进行了混合开发,而最简单,最 ... -
Android 方法引用数超过 65535 优雅解决
2017-03-31 09:37 1479随着应用不断迭代更新,业务线的扩展,应用越来越大(比如:集成了 ... -
android引用资源@与属性?备忘单
2017-03-30 10:09 1237几天前我偶然发现了我A ... -
ViewPager 与SwipeRefreshLayout,RecyclerView,ScrollView滑动冲突解决方法
2017-03-30 09:55 6518ViewPager 作为一个横向滚动的控件, 在 ViewGr ... -
Android中一些你可能没注意的小效果实现
2017-02-15 21:09 0http://www.see-source.com/blog/ ... -
Android热修复:Andfix和Hotfix,两种方案的比较与实现
2017-02-15 21:00 0http://www.see-source.com/blog/ ... -
Android 从网页中跳转到本地App
2017-01-11 09:27 1828我们在使用微信、QQ、京东等app的时候,会发现有时候通过他们 ... -
Activity的启动模式和onNewIntent
2016-12-28 09:10 1295一、启动模式介绍 启 ... -
android5.0使用Notification报RemoteServiceException的解决办法
2016-08-31 16:13 11465有时android5.0下使用Notification会报如下 ... -
RecyclerView 中的 item 如何居中问题
2016-05-18 09:52 12400一个很简单的Item布局,我只要让它由上而下排列,文字居中 ... -
sqlite3:not found 解决方法
2015-12-08 16:03 2503最最最重要,先root你的手机吧 sqlite3 为一个可 ... -
隐藏底部虚拟键NavigationBar实现全屏
2015-10-08 17:20 9799import android.app.Activity; ... -
服务端执行慢或网络延迟时,Volley多次发送请求的问题
2015-07-27 15:40 6941原文: Android Volley double post ... -
如何获取 Android 设备的CPU核数、时钟频率以及内存大小
2015-06-30 17:04 4324原帖: http://www.jianshu.com/p/f7 ... -
android点滴5
2015-04-10 17:32 2006一些小效果的实现 http://www.see-source. ...
相关推荐
在早期具有滚轮设备的android系统中以及现在的智能TV电视应用中视图的焦点控制就非常重要了。而在触摸设备上通常默认情况下只有EditText控件才具有焦点,而我们通常会遇到的一个问题就是当进入一个具有EditText的...
4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox的isChecked属性 4.5 消费券采购列表——多选项CheckBox的应用 4.6 向左或向右——...
4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox的isChecked属性 4.5 消费券采购列表——多选项CheckBox的应用 4.6 向左或向右——...
4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox的isChecked属性 4.5 消费券采购列表——多选项CheckBox的应用 4.6 向左或向右——...
4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox的isChecked属性 4.5 消费券采购列表——多选项CheckBox的应用 4.6 向左或向右——...
4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox的isChecked属性 4.5 消费券采购列表——多选项CheckBox的应用 4.6 向左或向右...
二、Android平台的发展前景 移动互联网的蓬勃发展促使手机终端产业链变化,应用和服务逐渐成为竞争的焦点。 无论是电信运营商,终端厂商还是应用开发商,目前都在向操作系统领域进军,试图对 内容的聚拢和对应用...
android 充值页面效果源码 1.要求是只能输入数字,最多小数点后两位,下方的充值金额小计一栏始终显示两位小数,除非金额为0,才可以显示为0。 2.GridView 的最后一项是EditText ,点击的时候不能在...
4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox的isChecked属性 4.5 消费券采购列表——多选项CheckBox的应用 4.6 向左或向右——...
4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox的isChecked属性 4.5 消费券采购列表——多选项CheckBox的应用 4.6 向左或向右——...
——具选择功能的对话框 3.21 Android变脸——主题(Theme)实现 第4章 史上超豪华的手机控件 4.1 EditText与TextView共舞——setOnKeyListener事件 4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给...
4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox的isChecked属性 4.5 消费券采购列表——多选项CheckBox的应用 4.6 向左或向右——...
4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox的isChecked属性 4.5 消费券采购列表——多选项CheckBox的应用 4.6 向左或向右——...
Android 一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导开发 IOS 由苹果公司开发的移动操作系统 Webkit 一个开源的浏览器引擎,在手机上的...
要完整演示应用程序的所有部分,我通常单击“启用隐藏功能”,然后确保启用以下内容: Android 通知操作笔记(演示提供自定义笔记) Spotify(启用从眼镜控制电话音频播放和音量) 任务(演示提供自定义任务) ...
1.1 目的及范围 随着科技的进步,手机的功能也不断的得到丰富,从最早的"大哥大"到现在的商务手机 ,只能手机,音乐手机等等,功能也从单纯的打电话发展到了发短信,听歌,上网……手 机和我们生活的联系越来越紧密...