Android Dialog圆角问题
2017-03-18 16:00
246 查看
这两天有一个需求:设置dialog圆角,写完后发现并没有达到效果,以前也碰到这个问题,这里记录下解决方案,便于查阅。也有百度去查询原因,却没有发现合适的解答,当然更可能是我没找到,还是自己解决吧。
Dialog与DialogFragment 解决方案一致:只要设置背景透明解决问题了。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
setContentView(view);
setCancelable(true);
}
/**
* Change the background of this window to a Drawable resource. Setting the
* background to null will make the window be opaque. To make the window
* transparent, you can use an empty drawable (for instance a ColorDrawable
* with the color 0 or the system drawable android:drawable/empty.)
*
* @param resId The resource identifier of a drawable resource which will
* be installed as the new background.
*/
public void setBackgroundDrawableResource(@DrawableRes int resId) {
setBackgroundDrawable(mContext.getDrawable(resId));
}
Dialog与DialogFragment 解决方案一致:只要设置背景透明解决问题了。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
setContentView(view);
setCancelable(true);
}
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //设置背景透明 getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); View view = View.inflate(getActivity(), R.layout.dialog_zntchain, null); return view; }看到这里,不难明白,应该是google自己设置了默认的背景,虽然我们设置了view为圆角,但是在挂在已有背景下,我们就是自然看不到,看下源码,google也有说道透明问题。
/**
* Change the background of this window to a Drawable resource. Setting the
* background to null will make the window be opaque. To make the window
* transparent, you can use an empty drawable (for instance a ColorDrawable
* with the color 0 or the system drawable android:drawable/empty.)
*
* @param resId The resource identifier of a drawable resource which will
* be installed as the new background.
*/
public void setBackgroundDrawableResource(@DrawableRes int resId) {
setBackgroundDrawable(mContext.getDrawable(resId));
}
相关文章推荐
- Android-自定义圆角Dialog遇到的问题
- android 关于Dialog 圆角的问题
- android dialog的圆角不显示问题
- Android中发送网络请求,弹出Dialog崩溃问题解决
- Android 系统点击屏幕Dialog会消失问题处理
- 用android dialog 时遇到的问题
- android dialog圆角显示及解决出现的黑色棱角.(友情提示)
- Android Alert Dialog解决点击按钮对话框不关闭的问题
- android 创建系统级的Dialog时,无法使用Home关闭的问题
- Android之Dialog问题のEditText
- Android圆角ListView并完美解决和ScrollView共存问题
- [Android]取得Dialog中EditText的内容问题
- 有关android中“Activity伪装”的Dialog问题的解决
- Android开发之AlertDialog 关于重写onCreatDialog自定义对话框的问题 问题出自于《疯狂Android讲义》这本书
- Android自定义Dialog对话框样式出现的边框无法填满问题
- android 自定义dialog 自定义dialog 宽度问题
- android shape显示圆角问题
- Android AlertDialog解决点击按钮立即消失的问题
- Android之Dialog问题のEditText
- Android圆角ListView并完美解决和ScrollView共存问题