在An“.NET研究”droid开发中如何移除EditText上的输入焦点
2011-10-20 21:56 狼人:-) 阅读(263) 评论(0) 编辑 收藏 举报当我们创建一个带EditText 或 AutoCompleteTextView的视图时,在加载视图时总是会把输入的焦点自动移动到第一个输入框。如下图所示:
下面是mail.xml布局文件:
1. <!--?xml version="1.0" encoding="utf-8"?-->
2. <linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
3. <button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/button_text">
4. </button>
5. <edittext android:hint="@string/hint" android:id="@+id/EditText01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="">
6. </edittext>
7. <button android:id="@+id/Button02" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/button_text">上海企业网站设计与制作yle="color: #000000;">
8. </上海闵行企业网站制作style="color: #000000;">button>
9. </linearlayout>
10.
我们如何才能把焦点从EditText上移除呢?最简单的方法是创建一个不可见的(invisible)LinearLayout,LinearLayout将会把焦点从EditText上移走。
我们修改mail.xml布局文件,在EditText之前增加一个LinearLayout ,如下所示:
1. <!--?xml version="1.0" encoding="utf-8"?-->
2. <linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
3. <button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/button_text">
4. </button>
5. <linearlayout android:focusable="true" android:focusableintouchmode="true" android:layout_height="0px" android:layout_width="0px">
6. 上海徐汇企业网站制作n><edittext android:hint="@string/hint" android:id="@+id/EditText01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="">
7. </edittext>
8. <button android:id="@+id/Button02" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text上海网站建设an style="color: #000000;">= "@string/button_text">
9. </button>
10. </linearlayout>
11. </linearlayout>
最终效果如下所示:
不需要任何代码就把焦点移除了,是不是最简单的解决方案?
希望本文对您有所帮助!
声明:此博有部分内容为转载,版权归原作者所有~
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南