android TouchMode下的focus问题
来源:互联网 发布:如何练硬笔书法知乎 编辑:程序博客网 时间:2024/06/05 04:34
今天试跑了"Google Android SDK开发范例大全源码里的EX04_02工程",发现mImageButton1.setOnFocusChangeListener这个监听器木有反应。查了很多资料发现原因是:在Android TouchMode模式下是不存在focus的。所谓的focus是指被选中的意思,类似于windows平台下单击一个文件夹后鼠标的焦点(focus)就在该文件夹上面。既然不存在focus,也就不存在FocusChange的问题,所以setOnFocusChangeListener监听器不起作用也就可以理解。如果想在TouchMode下面使用这个监听器可以使用如下两种方法:
1.增加一句代码:mImageButton1.setFocusableInTouchMode(true)
2.在main.xml中mImageButton标签中加入一个子标签:android:focusableInTouchMode="true"。这两种方法的作用都是使得focus在TouchMode下恢复作用。
关于TouchMode可以参考下面两片文章:
1.http://developer.android.com/resources/articles/touch-mode.html
2.http://hi.baidu.com/qmiao128/blog/item/3bc40f54e0605144574e0048.html
下面附上Google Android SDK开发范例大全源码里的EX04_02工程源代码
public class EX04_02 extends Activity { /*声明三个对象变量(图片按钮,按钮,与TextView)*/ private ImageButton mImageButton1; private Button mButton1; private TextView mTextView1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /*通过findViewById构造三个对象*/ mImageButton1 =(ImageButton) findViewById(R.id.myImageButton1); mButton1=(Button)findViewById(R.id.myButton1); mTextView1 = (TextView) findViewById(R.id.myTextView1); /*通过OnFocusChangeListener来响应ImageButton的onFous事件*/ mImageButton1.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View arg0, boolean isFocused) { // TODO Auto-generated method stub /*若ImageButton状态为onFocus改变ImageButton的图片 * 并改变textView的文字*/ if (isFocused==true) { mTextView1.setText("图片按钮状态为:Got Focus"); mImageButton1.setImageResource(R.drawable.iconfull); } /*若ImageButton状态为offFocus改变ImageButton的图片 *并改变textView的文字*/ else { mTextView1.setText("图片按钮状态为:Lost Focus"); mImageButton1.setImageResource(R.drawable.iconempty); } } }); /*通过onClickListener来响应ImageButton的onClick事件*/ mImageButton1.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub /*若ImageButton状态为onClick改变ImageButton的图片 * 并改变textView的文字*/ mTextView1.setText("图片按钮状态为:Got Click"); mImageButton1.setImageResource(R.drawable.iconfull); } }); /*通过onClickListener来响应Button的onClick事件*/ mButton1.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub /*若Button状态为onClick改变ImageButton的图片 * 并改变textView的文字*/ mTextView1.setText("图片按钮状态为:Lost Focus"); mImageButton1.setImageResource(R.drawable.iconempty); } }); } }
- android TouchMode下的focus问题
- android TouchMode下的focus问题
- Android View 的TouchMode
- android的focus问题
- Android的焦点(Focus)问题
- Android的焦点(Focus)问题
- Android的焦点(Focus)问题
- Android的焦点(Focus)问题 focusable
- Android 焦点Focus问题的总结
- EditText的focus问题
- qml的focus问题
- input的focus问题
- iOS下无法触发focus事件的问题
- focus 设置颜色的问题
- android 所有焦点问题汇总【Focus】
- android listview 第一次打开 无 focus 问题
- android 所有焦点问题汇总【Focus】
- android 所有焦点问题汇总【Focus】
- C++和Objective-C混编(官方文档翻译)
- C#/WPF 程序设计心得(二)
- STM32红外的实现
- Repository Pattern
- 搜索引擎爱好者博客
- android TouchMode下的focus问题
- 拖拽操作、拖拽光标设置(CTreeCtrl)
- Lucene学习总结之四:Lucene索引过程分析(1)
- ORA-00997: illegal use of LONG datatype
- 使用windows crypto API加密解密
- 解决linux窗口最小化在面板上发现不了的问题
- JAVA 如何将一个图形(以文件存在,如JPG或者GIF)画到窗体的画布中
- word使用技巧3---画各种随意的图像(肖像)
- JS采用click方式提交表达表单