调用对话框时更改默认的Android淡入/稀疏颜色 [英] Changing default Android fade/scrim color when calling a Dialog

查看:79
本文介绍了调用对话框时更改默认的Android淡入/稀疏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个应用程序,但是现在我需要在屏幕中间显示菜单窗口.

I've been working on an app and I've reaching the point where it requires me to display a menu window in the middle of the screen.

我一直在使用一个充满自定义View的AlertDialog对象,但是现在我需要用半透明的白色发光包围"窗口,而不是默认的灰色发光.我对应用程序中某些导航抽屉的淡入颜色做了类似的处理,但是在那种情况下,我有一种特定的方法可以快速帮助我解决该问题.到目前为止,我还没有发现任何可以帮助我解决这个问题的方法.

I've been using an AlertDialog object filled with a custom View but now it was required of me to "surround" the window with a semi-transparent white glow as opposed to the default grayish one. I did a similar with the fade-in color of some navigation drawers I have on my app but in that case I had a specific method to quickly help me solve that problem. So far I haven't found anything that helps me solve this one.

我尝试使用新的"windowBackground"值创建默认样式,但从一开始就遇到3个问题:

I tried creating a default style with a new "windowBackground" value but I encountered 3 problems from the get-go:

  • 我不再能够通过在布局外部单击来关闭AlertDialog(我猜是因为通过更改颜色使现在一切都成为布局)
  • 菜单窗口现在被以前没有的黑色轮廓包围
  • 通过在布局内部使用过滤搜索来操纵列表的成员,窗口会自行折叠

有什么方法可以直接或多或少地实现我想要的?

Is there any way to accomplish what I want more or less directly?

推荐答案

我不太确定,但是您可以在styles.xml中使用它

I'm not really sure about it, but you can use this in your styles.xml

<style name="MyDialogTheme" parent="android:Theme.AppCompat.Light.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/your_light_color</item>
<item name="android:backgroundDimEnabled">false</item>

如果要在外部单击时关闭该对话框,请使用以下方法:

And if you want to dismiss the dialog when clicking outside, use this:

dialog.setCanceledOnTouchOutside(true);

<item name="windowCloseOnTouchOutside">true</item>

在您的styles.xml中

in your styles.xml

这篇关于调用对话框时更改默认的Android淡入/稀疏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆