我有一个在清单文件中以对话框形式指定的活动,如下所示:
android:theme="@android:style/Theme.Dialog"
,那么如何防止软键盘将其推上并调整大小?android:theme="@android:style/Theme.Dialog"
,那么如何防止软键盘将其推上并调整大小?您可以简单地将活动的windowSoftInputMode标志切换为"adjustPan"。有关更多信息,请查看官方文档。
<activity
...
android:windowSoftInputMode="adjustPan|adjustResize">
</activity>
如果您正在使用ScrollView,请向ScrollView添加android:isScrollContainer="false"
。将 android:layout_height
设为固定值,而不是 match_parent
、fill_parent
或 wrape_content
。应该使用类似于 android:layout_height="480dp"
的固定数字。
或者我们可以在程序中指定它。
使用以下代码:
Functions.setActivityDiemention(this,
Functions.getScreenWidth(this) - 20,
Functions.getScreenHeight(this) - 20);
在 setContentView
之前
setActivityDiemention
代码
public static final void setActivityDiemention(Activity activity ,int width,int hieght) {
android.view.WindowManager.LayoutParams params = activity.getWindow()
.getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = params.width;
activity.getWindow().setAttributes(
(android.view.WindowManager.LayoutParams) params);
}
getScreenWidth
和 getScreenHeight
代码
public static int getScreenHeight(Activity activity) {
Display display = activity.getWindowManager().getDefaultDisplay();
Point size = new Point();
if (getAPILevel() < 13) {
return display.getHeight();
}
display.getSize(size);
return size.y;
}
public static int getScreenWidth(Activity activity) {
Display display = activity.getWindowManager().getDefaultDisplay();
Point size = new Point();
if (getAPILevel() < 13) {
return display.getWidth();
}
display.getSize(size);
return size.x;
}
必须使用
android:windowSoftInputMode="adjustPan">
TabActivity
编写的清单文件:<activity android:name="mypakage.fragment.fillinformation.ChosePopUpMenu" android:label="@string/title_activity_chose_pop_up_menu" android:theme="@android:style/Theme.Dialog" android:windowSoftInputMode="adjustPan"> </activity> - BlackRoot