您的位置:首页 > 其它

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

2017-09-05 09:45 393 查看
原地址: 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均可

就可解决进入界面就弹出键盘的问题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐