Android Dialog弹出时的软键盘弹出问题

来源:互联网 发布:股票分时线数据接口 编辑:程序博客网 时间:2024/05/17 02:54

在项目开发中遇见了Dialog弹出后软键盘死活不弹出的问题,只不过已经解决了。。。


content是Dialog中的EdiText,必须在Dialog初始化完成后,才能够弹出来
LayoutInflater inflater = LayoutInflater.from(context);LinearLayout inflate = (LinearLayout) inflater.inflate(R.layout.mydialog, null);mDialog=new Dialog(context);mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);mDialog.addContentView(inflate, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));TextView name = (TextView) inflate.findViewById(R.id.name_mydialog);final EditText content= (EditText) inflate.findViewById(R.id.content_mydialog);TextView cancle= (TextView) inflate.findViewById(R.id.cancle_mydialog);TextView sure= (TextView) inflate.findViewById(R.id.sure_mydialog);content.setFocusable(true);content.setFocusableInTouchMode(true);content.requestFocus();

content.post(newRunnable() {
@Override
public voidrun() {
InputMethodManager inputMethodManager=(InputMethodManager)((Activity)context). getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
});

0 0
原创粉丝点击