gpt4 book ai didi

java - 如何使对话框 fragment 背景不可见?

转载 作者:行者123 更新时间:2023-12-05 00:19:20 25 4
gpt4 key购买 nike

我在 Flow 的方法中使用了 youtuber Coding 来创建自定义对话框。我整天都在尝试使对话框的背景透明。我已经使用了我在网上找到的每一种方法。没有工作。

事情是这样的:

  • 首先是对话框布局layout_dialog.xml:

    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp"
    android:background="@drawable/dialog_background">

    <!-- The contents of the Dialog go here -->

    </RelativeLayout>

    <ImageView
    android:id="@+id/iconImageView2"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="0dp"
    android:background="?attr/actionBarItemBackground"
    android:scaleType="fitCenter"
    app:srcCompat="@android:mipmap/sym_def_app_icon" />

    </RelativeLayout>
  • 这是对话框类:

     public class DialogBrightness extends AppCompatDialogFragment {

    //declare whatever variables here

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.layout_dialog, null);

    builder.setView(view)
    .setTitle("Login")
    .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
    }
    })
    .setPositiveButton("ok", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
    //get whatever values
    listener.apply(//values);
    }
    });

    //findViewById for your dialog contents here

    return builder.create();
    }

    public interface DialogBrightnessListener {
    void apply(//values);
    }
    }
  • 这是从主 Activity 调用的对话框:

    DialogBrightness dialogBrightness = new DialogBrightness();
    dialogBrightness.show(getSupportFragmentManager(), "Brightness Dialog");

对话框是这样显示的:

enter image description here

我试图让顶部的白色部分不可见。什么都没用!

最佳答案

试试这个:

将下面的代码放在onCreateDialog中:

    // set the dialog background to transparent
getDialog().getWindow().setBackgroundDrawable(newColorDrawable(Color.TRANSPARENT));

// remove background dim
getDialog().getWindow().setDimAmount(0);

关于java - 如何使对话框 fragment 背景不可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63205115/

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