解决Dialog 消失,输入法不消失的问题
生活随笔
收集整理的這篇文章主要介紹了
解决Dialog 消失,输入法不消失的问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言:今天遇到一個奇怪的問題,Activity 里面彈出一個 dialog , 這個dialog里面有EditText 。
? ? ? ?問題:當 dialog 里面的輸入法出現的時候,此時讓diolog 消失,輸入法不消失。
?
效果圖如下:
? ??? ? ?
?
dialog 創建方法:
final AlertDialog.Builder builder = new AlertDialog.Builder(this);final AlertDialog dialog = builder.create() ;?
1、使用下面的代碼沒有效果
/*** 隱藏軟鍵盤*/void hideInput () {InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);if(inputMethodManager.isActive()){inputMethodManager.hideSoftInputFromWindow( this.getCurrentFocus().getWindowToken(), 0);}}
2、解決方法? ??
//隱藏輸入法InputMethodManager manager= (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);manager.hideSoftInputFromWindow( dialog.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);?
總結
以上是生活随笔為你收集整理的解决Dialog 消失,输入法不消失的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 自定义View之onMeasure()
- 下一篇: 自定义圆形控件 RoundImageVi