【问题标题】:How to prevent android soft keyboard from resizing my activity如何防止 android 软键盘调整我的活动大小
【发布时间】:2014-08-05 15:10:01
【问题描述】:

我有一个在Manifest 中指定为对话框的活动,就像这样

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

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

【问题讨论】:

    标签: android dialog android-softkeyboard


    【解决方案1】:

    您可以简单地将 Activity 的 windowSoftInputMode 标志切换为“adjustPan”。查看官方documentation了解更多信息。

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

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

    试试吧..

    【讨论】:

    • 是的,我试过了,但它对我不起作用,更具体地说,这个活动是一个 TabActivity,它包含 2 个标签
    • 这是我的清单 TabActivity &lt;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" &gt; &lt;/activity&gt;
    【解决方案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"> 
    

    【讨论】:

      猜你喜欢
      • 2013-06-16
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 2011-10-09
      • 1970-01-01
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      相关资源
      最近更新 更多