温馨提示×

温馨提示×

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

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

Android中Dialog该如何去除白色边框代码

发布时间:2021-10-14 15:42:00 来源:亿速云 阅读:108 作者:柒染 栏目:编程语言

这篇文章将为大家详细讲解有关Android中Dialog该如何去除白色边框代码,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

使用样式文件,在values 目录下新建styles.xml文件,编写如下代码:

<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的源码文件,里面的构造函数为如下:

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图片,所以就是为什么我们上边的样式文件要将其背景去除掉。这个东西搞了我好久,希望对你有帮助

前后效果对比

未设置前:

Android中Dialog该如何去除白色边框代码

设置后:

Android中Dialog该如何去除白色边框代码

关于Android中Dialog该如何去除白色边框代码就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

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

AI