1. 程式人生 > >android 底部Dialog裡面的EditText點選軟鍵盤頂起Dialog

android 底部Dialog裡面的EditText點選軟鍵盤頂起Dialog

最近專案需求要求做一個底部彈窗大概螢幕的1/3,上面有一個EditText,點選之後Dialog被這個輸入法擋住,現在要求Dialog隨之軟鍵盤被頂起。程式碼如下:

Dialog:

 final View view = LayoutInflater.from(this).inflate(R.layout.dialog, null);
        mDialog = new Dialog(this, R.style.dialogstyle);
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.show();
        Window window = mDialog.getWindow();
        window.setContentView(view);
        WindowManager.LayoutParams pl = window.getAttributes();
        pl.gravity=Gravity.BOTTOM;
        pl.width= WindowManager.LayoutParams.MATCH_PARENT;
        pl.height= WindowManager.LayoutParams.WRAP_CONTENT;
        window.getDecorView().setPadding(0, 0, 0, 0);
        window.setAttributes(pl);
       

Style:

<style name="dialogstyle">
        <item name="android:windowBackground">@android:color/white</item>
        <item name="android:windowFrame">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowContentOverlay">@null</item>
     
        <item name="android:windowFullscreen">true</item>
        <item name="android:backgroundDimEnabled">true</item>
    </style>

dialog_enter:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false" >
     <translate android:fromYDelta="100%"
                android:duration="300"/>

    <alpha android:fromAlpha="0.0" 
    	   android:toAlpha="1.0"
           android:duration="300" />

</set>

dialog_exit:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
    <translate android:toYDelta="100%"
               android:duration="300"></translate>
    <alpha
        android:duration="300"
        android:fromAlpha="1.0"
        android:toAlpha="0.0"/>

</set>