android去掉外面view,android去掉EditView的默认焦点问题

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

在网上找了好久,有点 监听软键盘事件,有点 调用 clearFouse()方法,但是测试了都没有! xml中也找不到相应的属性可以关闭这个默认行为

解决之道:在EditText的父级控件中找一个,设置成

代码如下

android:focusable="true"

android:focusableInTouchMode="true"

这样,就把EditText默认的行为截断了!

代码如下

style="@style/FillWrapWidgetStyle"

android:orientation="vertical"

android:background="@color/black"

android:gravity="center_horizontal"

android:focusable="true"

android:focusableInTouchMode="true"

>

android:id="@+id/logo"

style="@style/WrapContentWidgetStyle"

android:background="@drawable/dream_dictionary_logo"

/>

style="@style/FillWrapWidgetStyle"

android:background="@drawable/searchbar_bg"

android:gravity="center_vertical"

>

android:id="@+id/searchEditText"

style="@style/WrapContentWidgetStyle"

android:background="@null"

android:hint="Search"

android:layout_marginLeft="40dp"

android:singleLine="true"

/>

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

在xml中,在EditText控件之前

加入

代码如下

android:id="@+id/linearLayout_focus"

android:focusable="true"

android:focusableInTouchMode="true"

android:layout_width="0px"

android:layout_height="0px"/>

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值