gpt4 book ai didi

具有透明背景的android AlertDialog

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:55:29 24 4
gpt4 key购买 nike

我有一个自定义的 AlertDialog,我想让它的背景完全透明。通常要使 Activity 完全透明,我会执行以下操作

  • 在xml布局中将背景设置为#00000000

  • 在 list 中为 Activity 设置 android:theme="@android:style/Theme.Holo.Dialog"

  • 在 onCreate 中添加 getWindow().setBackgroundDrawable(new ColorDrawable(0))

    但是现在我正在处理一个对话框,我该如何实现透明度呢?

这是对话代码:

LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.activity_mine1,
(ViewGroup) findViewById(R.layout.mine1));
mine1 = new AlertDialog.Builder(this);
mine1.setView(dialoglayout);
mine1.show();

我的 xml 只是一个带有其他 subview 的 relativeLayout:

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

...

</RelativeLayout>

注意:我已经在这里看过一些类似的帖子,但它们似乎不起作用。

我真正的原因是我真正想要使用的背景不是矩形的。我让它在 Activity 中工作。但我想改用对话框。

编辑:

进一步尝试,我有这个 style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomDialog" parent="android:Theme.Holo.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
</resources>

我添加为

new AlertDialog.Builder(this, R.style.CustomDialog)

最佳答案

    <style name="CustomAlertDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:width">300dip</item>
<item name="android:textColor">#FFFFFF</item>
</style>

Dialog connectionDialog = new Dialog(this, R.style.CustomAlertDialog);
connectionDialog.setContentView(set your view here);
connectionDialog.show();

关于具有透明背景的android AlertDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17579017/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com