【发布时间】:2014-08-05 15:10:01
【问题描述】:
我有一个在Manifest 中指定为对话框的活动,就像这样
android:theme="@android:style/Theme.Dialog"
那么如何防止软键盘向上推和调整大小??
【问题讨论】:
标签: android dialog android-softkeyboard
我有一个在Manifest 中指定为对话框的活动,就像这样
android:theme="@android:style/Theme.Dialog"
那么如何防止软键盘向上推和调整大小??
【问题讨论】:
标签: android dialog android-softkeyboard
您可以简单地将 Activity 的 windowSoftInputMode 标志切换为“adjustPan”。查看官方documentation了解更多信息。
<activity
...
android:windowSoftInputMode="adjustPan|adjustResize">
</activity>
如果您正在使用 ScrollView,请将 android:isScrollContainer="false" 添加到 ScrollView。
试试吧..
【讨论】:
TabActivity,它包含 2 个标签
TabActivity <activity android:windowSoftInputMode="adjustPan" android:name="mypakage.fragment.fillinformation.ChosePopUpMenu" android:label="@string/title_activity_chose_pop_up_menu" android:theme="@android:style/Theme.Dialog" > </activity>
把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">
【讨论】: