如何防止android软键盘调整我的活动大小

Bla*_*oot 7 android dialog android-softkeyboard

我有一个活动,指定为此行的对话框,Manifest如下所示

android:theme="@android:style/Theme.Dialog"

那么如何防止软键盘上推和调整大小?

Lal*_*Lal 11

您只需将活动的windowSoftInputMode标志切换为"adjustPan"即可.查看官方文档以获取更多信息.

<activity
   ...
   android:windowSoftInputMode="adjustPan|adjustResize"> 
</activity>
Run Code Online (Sandbox Code Playgroud)

如果您正在使用ScrollView,请将此添加android:isScrollContainer="false"ScrollView.

试试吧..


Bla*_*oot -1

android:layout_height实心不是,match_parent它 应该是一个实心数字,例如或其他什么fill_parentwrape_contentandroid:layout_height="480dp"

或者我们可以通过编程方式指定它

使用此代码

Functions.setActivityDiemention(this,
            Functions.getScreenWidth(this) - 20,
            Functions.getScreenHeight(this) - 20);
Run Code Online (Sandbox Code Playgroud)

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);
}
Run Code Online (Sandbox Code Playgroud)

getScreenWidthgetScreenHeight

代码

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;
}
Run Code Online (Sandbox Code Playgroud)

并且必须使用

android:windowSoftInputMode="adjustPan"> 
Run Code Online (Sandbox Code Playgroud)