Android让EditText失去焦点避免自动弹出输入法
2016-04-01 10:36
405 查看
如果一进去activity,EditText就获取焦点,弹出输入法界面,无疑是很影响美观的。关于让EditText失去焦点,网上比较多的做法是添加一个visibility=gone的Textview.然后让这个textView获取焦点。不知道是我人品不好还是怎么的。我这样做不行,后来采用另外一种做法,就是在其父组件(布局)上添加以下两句代码:
[java]
view plain
copy
android:focusable="true"
android:focusableInTouchMode="true"
比如:
[html]
view plain
copy
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center_vertical"
android:background="#ffffff"
android:focusable="true"
android:focusableInTouchMode="true"
>
<EditText
android:layout_alignParentLeft="true"
android:id="@+id/searchWordET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:hint="姓名 单位名称 QQ 手机 电话 地址"
android:padding="10dp"
android:imeOptions="actionSearch"
android:singleLine="true"
android:textSize="13sp" />
</RelativeLayout>
[java]
view plain
copy
android:focusable="true"
android:focusableInTouchMode="true"
比如:
[html]
view plain
copy
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center_vertical"
android:background="#ffffff"
android:focusable="true"
android:focusableInTouchMode="true"
>
<EditText
android:layout_alignParentLeft="true"
android:id="@+id/searchWordET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:hint="姓名 单位名称 QQ 手机 电话 地址"
android:padding="10dp"
android:imeOptions="actionSearch"
android:singleLine="true"
android:textSize="13sp" />
</RelativeLayout>
相关文章推荐
- Jni开发与Android NDK开发学习笔记(一)
- android-时间选择器
- 自定义View的基本知识和步骤
- 菜鸟的Android学习笔记(二)
- Android Studio简单介绍与使用
- Android 65k 问题
- Android中FragmentTabHost结合fragment实现选项卡功能
- ViewPage,TabHost与Fragment(上)
- Android 退出应用程序问题
- E/AndroidRuntime: java.lang.IllegalStateException: Recursive entry to executePendingTransactions
- Android蓝牙3.0和4.0开发记录
- Android视图绘制流程完全解析,带你一步步深入了解View(二)
- android Matrix
- Android定时服务
- AMS管理android四大组件
- Android SystemProperties设置/取得系统属性的用法总结
- Android 设置EditText不会自动弹出键盘
- android 解压缩zip包
- Android EditText不弹出输入法总结,焦点问题的总结
- Android技术归档