Android 仿今日頭條評論時鍵盤自動彈出的效果:當點擊評論時,彈出對話框,同時彈出軟鍵盤,當點擊返回鍵時,將對話框關(guān)閉,不只是關(guān)閉軟鍵盤。
效果圖:

對這個對話框設(shè)置一個style效果:
<style name="inputDialog" parent="@android:style/Theme.Holo.Light.Dialog"> <item name="android:windowBackground">@color/dialog_bg</item> <!--背景--> <item name="android:windowFrame">@null</item> <!--設(shè)置無邊框--> <item name="android:windowNoTitle">true</item> <!-- 無標題 --> <item name="android:backgroundDimEnabled">true</item> <!-- 模糊 --> <item name="android:windowSoftInputMode">stateAlwaysVisible</item> <!--顯示軟件盤--> </style>
并設(shè)置Dialog的監(jiān)聽返回鍵事件,不然默認是隱藏軟鍵盤:
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent keyEvent) { if (keyCode == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0) dialog.cancel(); return false; } }); 做完以上兩步,就可以實現(xiàn)與今日頭條評論一樣的效果了。
新聞熱點
疑難解答
圖片精選