Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 透明对话框不';有些设备不能工作_Android_User Interface - Fatal编程技术网

Android 透明对话框不';有些设备不能工作

Android 透明对话框不';有些设备不能工作,android,user-interface,Android,User Interface,我正在使用此代码应用具有渐变背景的颜色 dialog.getWindow().setBackgroundDrawable(new ColorDrawable(MyColor)); 它在我的手机上运行得很好,但在我的平板电脑上却不起作用 在我的拨号上显示白色和灰色背景(我使用自定义视图,背景设置为@null): 这对我很有效: alertDialog.getWindow().setBackgroundDrawableResource(android.R.color.transpa

我正在使用此代码应用具有渐变背景的颜色

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(MyColor));
它在我的手机上运行得很好,但在我的平板电脑上却不起作用

在我的拨号上显示白色和灰色背景(我使用自定义视图,背景设置为@null):

这对我很有效:

        alertDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

如果没有,请查看

您可以尝试此方法,但似乎这已经被建议了

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
相反,你试过这样的东西吗

 <style name="TransparentDialogTheme" parent="android:Theme.Holo.Dialog.NoActionBar">
     <item name="android:windowBackground">@color/transparent</item>
     <item name="android:colorBackgroundCacheHint">@null</item>
 </style>
这有点过分,但如果您确实需要,也可能需要:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="TransparentDialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@color/orange_transparent</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:gravity">center</item>
</style>

</resources>

@空的
@颜色/橙色透明
假的
@空的
@空的
@空的
@android:style/Animation.Dialog
状态未指定|调整盘
居中

问题在于,AlertDialog builder实际上不适合设计透明对话框,并且始终具有黑色背景,而黑色背景实际上是它的主题,请使用对话框来创建透明主题

示例:

alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.show();

使用Dialog不需要对透明背景进行任何主题操作,因此基本上很简单。

我建议只创建一个具有透明背景的活动,然后您可以根据需要在活动中显示任何您想要的内容,并轻松地对其进行自定义。这里有一些东西可以让你开始

在我尝试在我的应用程序中实现类似于显示繁忙屏幕的功能时,我得到了很多帮助。我希望你觉得这有帮助,让我知道你走了哪条路。祝你好运

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
这将是良好的api低于lolipop和以上或lolipop使用

android:background="@android:color/transparent"

在对话框片段的父布局中,简单地说,在所有api中都使用这两种方法来解决这个问题。

根据您的帖子,我有一些问题可能会导致透明度方面的问题

1。-由于您的平板电脑显示了不同的渲染,可能是操作系统API低于您手机上的版本?如果是这种情况,请尝试使用与手机操作系统API相匹配的适当支持库

2。-假设两个设备在OS API上相似,您可以尝试两种不同的方法

a)将零作为可着色的参数传递:)

b)创建一个不同的活动,只需显示您的对话框并隔离与父活动相关的主题(这肯定是导致问题的原因),执行以下操作。


您可以将此方法应用于对话框、显示演示屏幕或教学所需的活动:)

首先添加如下样式

<style name="customStyleDialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:background">@android:color/transparent</item>
</style>
确保通过在视图上添加设置为此对话框的背景色

.setContentView(--);
在对话框中使用主题

<style name="Dialog_Transparent" parent="@android:style/Theme.Dialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>


public class RProgressDg extends Dialog {

    public RProgressDg(Context context) {
        this(context, R.style.Dialog_Transparent);
    }

    public RProgressDg(final Context context, int theme) {
        super(context, theme);
        this.setContentView(R.layout.dg_pro_round);
    }

}

@空的
真的
真的
@android:彩色/透明
假的
真的
@空的
“公共类RProgressDg扩展”对话框{
公共RProgressDg(上下文){
这(上下文、R.style.Dialog_透明);
}
公共RProgressDg(最终上下文,int主题){
超级(上下文、主题);
这个.setContentView(R.layout.dg_pro_round);
}
}
使用以下方法:

alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
  alertDialog.show();

您还需要禁用dim:

Window w = dialog.getWindow();
w.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
LayoutParams lp = w.getAttributes();
lp.flags &= ~LayoutParams.FLAG_DIM_BEHIND; 
lp.dimAmount = 0;
w.setAttributes(lp);

我会在晚上看到我的代码,但我的手机是api 23(工作正常),我的平板电脑是api 19(不要担心,图像有问题)。请告诉我进展如何。minSdkVersion 19 targetSdkVersion 23亲爱的rcorbellini,我很高兴你收到了:)我花在bountry的时间结束了,我还不能测试它,但我认为你的答案是最好的。这正是我所使用的,我的“新彩色可绘制(MyColor)”是一种透明的颜色,我的自定义xml有一个透明的背景
Dialog dialog = new Dialog(getActivity(), R.style.customStyleDialog);
// other settings to the dialog
// for making work transparency on low level devices add next line too after show
// dialog 

dialog.show();
dialog.getWindow().setBackgroundDrawable(newColorDrawable(android.graphics.Color.TRANSPARENT));
.setContentView(--);
<style name="Dialog_Transparent" parent="@android:style/Theme.Dialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>


public class RProgressDg extends Dialog {

    public RProgressDg(Context context) {
        this(context, R.style.Dialog_Transparent);
    }

    public RProgressDg(final Context context, int theme) {
        super(context, theme);
        this.setContentView(R.layout.dg_pro_round);
    }

}
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
  alertDialog.show();
Window w = dialog.getWindow();
w.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
LayoutParams lp = w.getAttributes();
lp.flags &= ~LayoutParams.FLAG_DIM_BEHIND; 
lp.dimAmount = 0;
w.setAttributes(lp);