原文网址:http://www.111cn.net/sj/android/54680.htm

做一个输入框时发现android中EditView的默认焦点了,这种问题如果是在输入框还好,但在搜索页面或浏览页面这样就会影响用户体验了,那要如何取消EditView的默认焦点呢,下面我们来看看。

在网上找了好久,有点 监听软键盘事件,有点 调用 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>

查阅了很多资料后,发现以下方法最简单:

在xml中,在EditText控件之前
加入

代码如下 复制代码

<LinearLayout
android:id="@+id/linearLayout_focus"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>

这是一个虚假的LinearLayout,不会显示的,但是会抢走焦点

更多相关文章

  1. Android(安卓)实现全屏 去掉标题栏
  2. Google Admob广告Android(安卓)、简单应用
  3. Android日记之2012\01\13
  4. Android高手进阶教程(十五)---Android中万能的BaseAdapter(Spinn
  5. Android(安卓)开发中常见的Eclipse排版设置
  6. 2018-05-27
  7. Tiny4412——Android访问硬件的方法
  8. Android应用自动更新功能的实现!!!
  9. ios开发之ios中控件

随机推荐

  1. android流量统计
  2. Android将死,Web OS才是王道——通过Googl
  3. Android淘宝好评星级进度条RatingBar原来
  4. Android进程永生技术终极揭秘:进程被杀底
  5. android AutoCompleteTextView 实现输入
  6. Android中隐藏ActionBar的方法
  7. Android获取手机方向
  8. android带图片的AlertDialog和文件管理器
  9. Android Button 点击时替换背景颜色和替
  10. 做了六年Android,终于熬出头了,15K到31K全