获取屏幕宽度的代码如下
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
screenwidth=dm.widthPixels;
将自定义dialog宽度设置为获取的screenwidth后,在调出dialog的时候周围还是有一圈空白的不能充满,如下图
这种情况应该怎么办
还有另外一个问题就是,我想在调出dialog的同时自动弹出软键盘,应该要怎么实现
有获取到屏幕宽度,后来发现是因为背景色是透明的导致周围少了一圈,加上下面这句把背景色设置成白色就解决问题了
inputDialog.getWindow().getDecorView().setBackgroundResource(R.color.white);
dialog宽:可能和style有关、Theme、布局文件中的margin、padding等。
软键盘的相关代码:
inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
public void hintKeyBoard() {
if (inputMethodManager.isActive() && getCurrentFocus() != null) {
if (getCurrentFocus().getWindowToken() != null) {
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
}
}
}
public void showKeyBoard(EditText view) {
if (inputMethodManager.isActive() && getCurrentFocus() != null) {
if (getCurrentFocus().getWindowToken() != null) {
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_FORCED);
}
}
}