Android自定义对话框背景 [英] android custom dialog background

查看:280
本文介绍了Android自定义对话框背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的Android应用程序中显示一个自定义对话框.标准的AlertDialog设计是不可接受的. Android文档说:

I need to show a custom dialog in my Android application. Standard AlertDialog design is unacceptable. Android docs say:

提示:如果要自定义对话框,则可以显示一个活动" 作为对话框而不是使用Dialog API.只需创建一个 活动并将其主题设置为 清单元素:

Tip: If you want a custom dialog, you can instead display an Activity as a dialog instead of using the Dialog APIs. Simply create an activity and set its theme to Theme.Holo.Dialog in the manifest element:

就是这样.该活动现在显示在对话框窗口中,而不是 全屏.

That's it. The activity now displays in a dialog window instead of fullscreen.

听起来很有希望.我做到了,但是透明度不起作用!背景始终为灰色:

Sounded promising. I did it, but transparency does not work! Background is always grey:

清单上有一个desc:

Here is a desc in the manifest:

<activity
    android:name=".MyDialogActivity"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Holo.Dialog.NoActionBar" >
</activity>

这是我活动的根源:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="#00000000"
    android:layout_width="400dp"
    android:layout_height="wrap_content" >

    // Content ... //

</RelativeLayout>

我也尝试过android:background="@null"-效果是一样的. 如果我使用android:background="#ff0000",那么它是红色的(应该是红色的).但是如何使其透明?

I tried also android:background="@null" - effect was the same. If I use android:background="#ff0000" then it's red (as it should be). But how do I make it transparent?

更新

我最终以

<style name="MyThemeDialogCustom" parent="android:Theme.Holo.Dialog.NoActionBar" >
    <item name="android:windowBackground">@color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
</style>

推荐答案

将主题设置为

<style name="ThemeDialogCustom">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
</style>

这篇关于Android自定义对话框背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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