android dialog 软键盘

最终结果:

android dialog 软键盘


项目中需要用到自定义弹框, 当其中有Edittex控件时, 默认不弹出软键盘,解决办法:为Edittext设置  onFocusChangeListener监听函数,具体代码如下:

Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.show();
dialog.getWindow().setBackgroundDrawable(
activity.getResources().getDrawable(
R.drawable.bg_trans));
dialog.setContentView(R.layout.layout_dialog_drug_name);
final com.jianhai.health.view.ClearEditText et = (ClearEditText) dialog
.findViewById(R.id.id_et_change);
et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
   @Override
   public void onFocusChange(View v, boolean hasFocus) {
       if (hasFocus) {
            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
       }
   }
});


你可能感兴趣的:(dialog,软键盘,不显示)