Android中Activity中某个EditText被clearFocus后其他控件(别的EditText)也不要获得焦点
来源:互联网 发布:百度云域名查询 编辑:程序博客网 时间:2024/04/30 11:28
from:http://www.crifan.com/android_activity_edittext_after_clearfocus_other_control_not_get_focus/
【问题】
当然Activity中,当某个EditText被clearFocus后,结果focus又跑到当前页面中第一个可以获得焦点的控件:别的EditText
此处希望别的没有任何控件去获得焦点。
【折腾过程】
1.搜:
android edittext clearFocus got focus again
参考:
使用TextView/EditText应该注意的地方 – xiaoguozi’s Blog – C++博客
待会可以去试试:
requestFocus
2.搜:
android clearFocus get focus again
参考:
android – How to remove focus without setting focus to another control? – Stack Overflow
其是间接实现:
当取消了一个EditText的focus后,不要让焦点跑到其他控件(尤其是另外的,或者是界面中第一个EditText)
则可以:
对于EditText的parent级别的,一般都是LinearLayout,对他们设置:
android:focusable="true"
android:focusableInTouchMode="true"
这样,当取消了子控件EditText的focus后,focus就自动跑到上一级的view了,即此处的LinearLayout了。
所以去试试:
LinearLayout singleTabAllGroup =
new
LinearLayout(mTabContext);
singleTabAllGroup.setLayoutParams(
new
LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
singleTabAllGroup.setOrientation(LinearLayout.VERTICAL);
//singleTabAllGroup.setOrientation(LinearLayout.HORIZONTAL);
singleTabAllGroup.setPadding(
4
,
4
,
4
,
4
);
singleTabAllGroup.setBackgroundColor(getResources().getColor(R.color.TabPageBackgroudColor));
变为:
LinearLayout singleTabAllGroup =
new
LinearLayout(mTabContext);
singleTabAllGroup.setLayoutParams(
new
LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
singleTabAllGroup.setOrientation(LinearLayout.VERTICAL);
//singleTabAllGroup.setOrientation(LinearLayout.HORIZONTAL);
singleTabAllGroup.setPadding(
4
,
4
,
4
,
4
);
singleTabAllGroup.setBackgroundColor(getResources().getColor(R.color.TabPageBackgroudColor));
//for got lost focus from child EditText
singleTabAllGroup.setFocusable(
true
);
singleTabAllGroup.setFocusableInTouchMode(
true
);
看看效果:
然后基本实现了所需要的效果:
当子的EditText失去焦点后,父级的LinearLayout好像是获得了焦点。
3.不过,对于其他级别的view,也去添加了对应的代码:
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<LinearLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:baselineAligned=
"false"
android:orientation=
"vertical"
android:focusable=
"true"
android:focusableInTouchMode=
"true"
>
......
</LinearLayout>
和:
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<RelativeLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:paddingLeft=
"20sp"
android:orientation=
"horizontal"
android:focusable=
"true"
android:focusableInTouchMode=
"true"
>
......
</RelativeLayout>
【总结】
想要一个EditText失去焦点后,其他控件(尤其是别的可以编辑的EditText)不要获得焦点,则可以:
对于该EditText的父级控件(一般都是LinearLayout),设置对应的focusable和focusableInTouchMode为true:
xml中写法为:
android:focusable="true"
android:focusableInTouchMode="true"
代码中为:
edittextView.setFocusableInTouchMode(
true
);
这样,当子级的EditText失去焦点后,父级的LinearLayout就可以获得焦点
->别的(可编辑的EditText)控件就不会获得焦点了。
- Android中Activity中某个EditText被clearFocus后其他控件(别的EditText)也不要获得焦点
- Android中取消EditText自动获得焦点
- 【项目中】禁止进入activity后EditText自动获得焦点的方法
- Activity中EditText焦点问题
- EditText的clearFocus() :让EditText失去焦点
- EditText的clearFocus() :让EditText失去焦点
- android EditText获得焦点后 底部控件被软键盘覆盖
- Android中EditText点击获得焦点后无法显示输入法键盘
- Android中EditText点击获得焦点后无法显示输入法键盘
- android中当EditText获得焦点时屏幕下面的控件移位
- android中当EditText获得焦点时屏幕下面的控件移位
- Android中EditText焦点问题
- EditText clearFocus
- EditText clearFocus
- 禁止进入activity后EditText自动获得焦点的方法
- Edittext在xml文件中设置android:focusable=“false”之后,edittext再次获得焦点。
- Android启动Activity之后阻止EditText自动获得焦点
- Android 中获取EditText控件的焦点以及监听他的内容让焦点自动跳转到下一个EditText控件
- 软件开发基本认知观
- session的断点续传
- linux运维实用的42个常用命令总结
- C++构造函数初始化列表与赋值
- 第一行代码笔记 下拉刷新卡片现实上滑隐藏标题栏的demo
- Android中Activity中某个EditText被clearFocus后其他控件(别的EditText)也不要获得焦点
- Android 监听EditText 使Button是否能可用工具类
- JS删除Cookies操作
- linux笔记---程序函数
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- 搬家
- 简单谈谈对C++设计模式的理解
- MySQL基本操作
- K8S对node添加label,并根据label筛选节点