原地址: 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均可
就可解决进入界面就弹出键盘的问题