一、在activity的AndroidManifest中把属性设置为
<activity android:name=".views.CustomTitleBarInputMethodActivity" android:theme="@style/Theme.AppCompat.Light.NoActionBar" android:windowSoftInputMode="adjustResize|stateHidden"></activity>
二、把布局文件用scrollview包裹住:(注意在布局中添加android:fitsSystemWindows="true"属性)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#055ac4" android:fitsSystemWindows="true" tools:context="com.konstant.konstanttools.views.CustomTitleBarInputMethodActivity"> <!--用来作为自定义的状态栏--> <TextView android:layout_width="match_parent" android:layout_height="50dp" /> <!--把内部控件包裹住--> <ScrollView android:background="#fff" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <ImageView android:layout_width="match_parent" android:layout_height="400dp" android:src="@mipmap/ic_launcher" /> <EditText android:id="@+id/edit" android:layout_width="match_parent" android:layout_height="50dp" android:hint="在这里输入文字" /> <EditText android:layout_width="match_parent" android:layout_height="50dp" android:hint="第二行文字" /> <Button android:layout_width="match_parent" android:layout_height="50dp" /> </LinearLayout> </ScrollView> </LinearLayout>