(转)EditText 焦点控制,进入界面时不弹出键盘

原地址: http://blog.csdn.net/DxhToStage/article/details/51523808


刚刚进入界面弹出软键盘,是一件让用户体验非常不好的事情,解决这个问题只需要在布局文件添加两行代码即可搞定

       

实现此布局的部分代码如下:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<android.support.v7.widget.Toolbar
    android:id="@+id/classify_toolbar"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#ff0000">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left"
    android:src="@mipmap/return_iv"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="50dp"
    android:text="分类"
    android:textColor="#faf9fa"
    android:textSize="15sp"/>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="true"    //加这两句
    android:focusableInTouchMode="true">    //

<EditText
    android:id="@+id/et_search"
    android:layout_width="220dp"
    android:layout_height="25dp"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="5dp"
    android:background="@drawable/shape_search"
    android:hint="请输入搜索内容"
    android:textSize="15sp"/>



只需要在包含EditText的布局中加入

  android:focusable="true"
  android:focusableInTouchMode="true"

添加在最外层LinearLayout或RelativeLayout均可

就可解决进入界面就弹出键盘的问题

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值