温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android对话框Dialog 的一点小问题

发布时间:2020-07-05 20:00:02 来源:网络 阅读:534 作者:拾荒者老大 栏目:移动开发

为了在对话框中使用editText输入文字,别的自定义方法都没用,得这样:

Dialog dialog = new Dialog(context);

但这样会有个讨厌的title,所以得去掉:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

在自定义对话框时,有时候需要宽度全屏,但部分Activity的主题会有问题,所以需要加上:

Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(lp);

有些继承AlertDialog的自定义对话框则需要写在onCreate()方法里.

打开对话框时显示软键盘:

 dialog.getWindow().setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);




if(manager==null)
			manager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
		manager.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
		final View btn0 = window.findViewById(R.id.pop_index_store_creat_btn0);
		btn0.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				manager.hideSoftInputFromWindow(edit0.getWindowToken(),0);
				dialogActive.dismiss();
			}
		});


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI