关于android:focusable属性 - daishuguang
2015-09-21 14:39
387 查看
在项目中,一进入一个页面, EditText默认就会自动获取焦点。
那么如何取消这个默认行为呢?
在网上找了好久,有点 监听软键盘事件,有点 调用 clearFouse()方法,但是测试了都没有! xml中也找不到相应的属性可以关闭这个默认行为
解决之道:在EditText的父级控件中找一个,设置成
android:focusable="true" android:focusableInTouchMode="true"
这样,就把EditText默认的行为截断了!
<LinearLayout
style="@style/FillWrapWidgetStyle"
android:orientation="vertical"
android:background="@color/black"
android:gravity="center_horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
>
<ImageView
android:id="@+id/logo"
style="@style/WrapContentWidgetStyle"
android:background="@drawable/dream_dictionary_logo"
/>
<RelativeLayout
style="@style/FillWrapWidgetStyle"
android:background="@drawable/searchbar_bg"
android:gravity="center_vertical"
>
<EditText
android:id="@+id/searchEditText"
style="@style/WrapContentWidgetStyle"
android:background="@null"
android:hint="Search"
android:layout_marginLeft="40dp"
android:singleLine="true"
/>
</RelativeLayout>
</LinearLayout>
来自:http://blog.csdn.net/woshicaixianfeng/article/details/7261718 灰常感谢这位同学。。。
还有一个方法也可以非常简单的实现这个功能:
EditText对象的clearFocus();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editMsgView.getWindowToken(), 0);(关闭软键盘。。。)
那么如何取消这个默认行为呢?
在网上找了好久,有点 监听软键盘事件,有点 调用 clearFouse()方法,但是测试了都没有! xml中也找不到相应的属性可以关闭这个默认行为
解决之道:在EditText的父级控件中找一个,设置成
android:focusable="true" android:focusableInTouchMode="true"
这样,就把EditText默认的行为截断了!
<LinearLayout
style="@style/FillWrapWidgetStyle"
android:orientation="vertical"
android:background="@color/black"
android:gravity="center_horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
>
<ImageView
android:id="@+id/logo"
style="@style/WrapContentWidgetStyle"
android:background="@drawable/dream_dictionary_logo"
/>
<RelativeLayout
style="@style/FillWrapWidgetStyle"
android:background="@drawable/searchbar_bg"
android:gravity="center_vertical"
>
<EditText
android:id="@+id/searchEditText"
style="@style/WrapContentWidgetStyle"
android:background="@null"
android:hint="Search"
android:layout_marginLeft="40dp"
android:singleLine="true"
/>
</RelativeLayout>
</LinearLayout>
来自:http://blog.csdn.net/woshicaixianfeng/article/details/7261718 灰常感谢这位同学。。。
还有一个方法也可以非常简单的实现这个功能:
EditText对象的clearFocus();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editMsgView.getWindowToken(), 0);(关闭软键盘。。。)
相关文章推荐
- Android Activity之间切换出现短暂黑屏的处理方法
- android 之 下载管理器 无论监测在当地的设计思路
- BaseAbsActivity的使用
- Android开发之利用XMPP协议实现消息的即时推送
- android webview goBack()之后 getUrl()无效问题
- android事件传递机制的详细了解
- 性能优化——Android内存优化
- Android中集成QQ登陆和QQ空间分享
- android studio shortcut
- 【Android】开源项目汇总-备用 各种图形的绘制,各种效果
- Android学习笔记:Android异步任务之AsyncTask基础
- Android之给gridview的单元格加上分割线
- android 调用系统相机返回activity被销毁
- 【android】用EditText控件和Button控件实现一个简易计算器
- Android-透明半透明效果
- Android Studio安装、配置
- Android APK 瘦身处理
- mac版本android studio 较为常用的快捷键
- Android混淆编译
- 14.Android 控制Handler内存泄露 技巧