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

时间:2014-08-05 15:10:02

标签: android dialog android-softkeyboard

我在Manifest这样的

中指定了与此行对话的活动

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

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

2 个答案:

答案 0 :(得分:10)

您只需将活动的windowSoftInputMode标记切换为" adjustPan"。查看官方documentation了解更多信息。

<activity
   ...
   android:windowSoftInputMode="adjustPan|adjustResize"> 
</activity>

如果您使用的是ScrollView,请将此android:isScrollContainer="false"添加到ScrollView

试试..

答案 1 :(得分:-2)

android:layout_height固定为match_parentfill_parentwrape_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);
}

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;
}

并且必须使用

android:windowSoftInputMode="adjustPan"> 
相关问题