先上两张图
第一张问题很明显,第二张是成功的图,
其实第一张是加了
//getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); // InputMethodManager imm = (InputMethodManager) // getSystemService(INPUT_METHOD_SERVICE); // imm.showSoftInput(layout, 0); //显示软键盘 // imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); //显示软键盘
这段代码,自动弹出来的,结构被遮挡了,查了一番资料也没解决,一群里哥们提示了一句代码,结果成功了,爽,
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
就是这么神奇,
下面把我整个showdialog方法贴出来吧;
public void showLogoutDialog(final int charnum,final String title) { LayoutInflater layoutInflater =LayoutInflater.from(this); RelativeLayout layout = (RelativeLayout)layoutInflater.inflate(R.layout.change_mes_dialog, null ); final Dialog dialog = new AlertDialog.Builder(MimeDetailActivity.this).create(); dialog.show(); dialog.getWindow().setContentView(layout); dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); //getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); // InputMethodManager imm = (InputMethodManager) // getSystemService(INPUT_METHOD_SERVICE); // imm.showSoftInput(layout, 0); //显示软键盘 // imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); //显示软键盘 TextView tex=(TextView)layout.findViewById(R.id.dialog_text); TextView tex1=(TextView)layout.findViewById(R.id.textView_title); tex.setMovementMethod(ScrollingMovementMethod.getInstance()); tex1.setText("修改提示"); tex.setText(title); edit = (EditText) layout.findViewById(R.id.edit_caonimalebi); edit.addTextChangedListener(myWatcher); //监听edittext charnum_tx=(TextView)layout.findViewById(R.id.charnum_tx); //确定按钮 Button btnOK = (Button) layout.findViewById(R.id.dialog_ok); btnOK.setText("更新"); btnOK.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(edit.getText().length()>charnum){ Toast.makeText(MimeDetailActivity.this, "字数超限", Toast.LENGTH_SHORT).show(); }else{ new Up().execute(); //dialog.dismiss(); } } }); //btnOK.setClickable(btn); //关闭按钮 ImageButton btnClose = (ImageButton) layout.findViewById(R.id.dialog_close); btnClose.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); }
中间还使用了对edittext的监听,来判断输入的字的个数,防止输入超限,,,,
这个监听呢,edit这还出来不少问题,
edit = (EditText) layout.findViewById(R.id.edit_caonimalebi);玩玩没想到忽略了layout,导致程序总是崩溃,唉,粗心了,
这个edittext的监听也贴出来
TextWatcher myWatcher = new TextWatcher(){ @Override public void afterTextChanged(Editable s) { // TODO 自动生成的方法存根 charnum_tx.setText("您还可以输入"+(charnum - edit.getText().length())+" \ "+charnum); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO 自动生成的方法存根 } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO 自动生成的方法存根 } };
唉收工,累死了,谢谢好人。