制作提示对话框背景透明

制作提示对话框背景透明

本文介绍了制作提示对话框背景透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建Android上的糖豆OS警告对话框。一切运作良好,但我想要的是不是警告对话框的黑色背景我希望有一个透明背景。我看了这么多文章和用户对计算器,但其中没有一个是帮助我的问题。

I am creating an alert dialog on Android Jelly Beans OS. Everything works well but what I want is that instead of the black background of the alert dialog I want a transparent background. I read so many articles and user's question on stackoverflow but none of them is helping me out.

下面是我的code:

AlertDialog.Builder builder =  new AlertDialog.Builder(this, R.style.CustomAlertDialog);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog1, int which) {
            gActivityResult = REQUEST_PICK_CONTACT;
            onResume();
            return;
        } });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog1, int which) {
            return;
        } });
    View view = getLayoutInflater().inflate(R.layout.alert_dialog, null);
    builder.setTitle(R.string.gender_age);
    builder.setInverseBackgroundForced(false);
    builder.setView (view);


    dialog = builder.create ();

下面是我的CustomAlertDialog这是在res /价值/ styles.xml定义

Here is my CustomAlertDialog which is defined in res/values/styles.xml

<style name="CustomAlertDialog" parent="@android:style/Theme.Dialog">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <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_color</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:gravity">left</item>
</style>

下面是color.xml

Here is the color.xml

<resources>
   <color name="transparent_color">#00000000</color>
</resources>

但它并没有帮助我。

But it didn't help me.

我的问题:这是可行的?如果是的话,可以请你指导我在正确的方向?

My question: Is this doable? If yes, can you please guide me in the right direction?

推荐答案

如果您还没有读过Style自定义属性的风格AlertDialog 的问题,你应该继续阅读。答案建议使用对话框而不是警报对话框。而且阅读问题意识与 LayoutInflater 清除可能多一点。希望它帮助。试试吧,让我知道,如果它的工作原理。

If you haven't read Style attributes of custom styled AlertDialog question, you should go ahead and read. The answer suggests to use Dialog instead of Alert Dialog. Moreover reading Making sense of LayoutInflater issue with LayoutInflater might clear a bit more. Hope it helps. Try it and let me know if it works.

这篇关于制作提示对话框背景透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 07:15