当前位置: 移动技术网 > 移动技术>移动开发>Android > android dialog边框去除白色边框实现思路及代码

android dialog边框去除白色边框实现思路及代码

2019年07月24日  | 移动技术网移动技术  | 我要评论
使用样式文件,在values 目录下新建styles.xml文件,编写如下代码:
复制代码 代码如下:

code highlighting produced by actipro codehighlighter (freeware)http://www.codehighlighter.com/--><resources>
<style name="dialog" parent="@android:style/theme.dialog">
<item name="android:windowframe">@null</item>
<item name="android:windowisfloating">true</item>
<item name="android:windowistranslucent">false</item>
<item name="android:windownotitle">true</item>
<item name="android:background">@android:color/black</item>
<item name="android:windowbackground">@null</item>
<item name="android:backgrounddimenabled">false</item>
</style>
</resources>

调用时,使用alerdialog的接口类,dialog 接口编写如下代码: 
复制代码 代码如下:

dialog dialog = new dialog(setactivity.this, r.style.dialog);
dialog.setcontentview(r.layout.test);
dialog.show();

下面我们查看一下dialog的源码文件,里面的构造函数为如下
复制代码 代码如下:

code highlighting produced by actipro codehighlighter (freeware)http://www.codehighlighter.com/-->public dialog(context context, int theme) {
mcontext = new contextthemewrapper(
context, theme == 0 ? com.android.internal.r.style.theme_dialog : theme);
mwindowmanager = (windowmanager)context.getsystemservice("window");
window w = policymanager.makenewwindow(mcontext);
mwindow = w;
w.setcallback(this);
w.setwindowmanager(mwindowmanager, null, null);
w.setgravity(gravity.center);
muithread = thread.currentthread();
mdismisscancelhandler = new dismisscancelhandler(this);
}

这里面我们可以看出,android 使用了默认的构造函数为dialog 设置样式,如果没有为其设置样式,即默认加载事先编写好的样式文件,dialog 一共由多个9.png的图片构成,大部分都是带有边框的9.png图片,所以就是为什么我们上边的样式文件要将其背景去除掉。这个东西搞了我好久,希望对你有帮助
前后效果对比

未设置前:

设置后:

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网