gpt4 book ai didi

Android透明DialogFragment

转载 作者:太空狗 更新时间:2023-10-29 15:32:33 25 4
gpt4 key购买 nike

我有一个对话框 fragment ,它在 WidgetConfig Activity 运行时显示。该对话框显示了一个列表,用户可以从中选择一些项目。我希望这个对话框是透明的,这样你就可以在对话框的背景中看到主屏幕。这是我目前在 WidgetConfig Activity 中所做的:

    DialogFragment dialog = new myChooserDialog();  
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show(getFragmentManager(), "dialog");

编辑:myChooserDialog 的代码:

public class MyChooserDialog extends DialogFragment{

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
choices = getResources().getStringArray(R.array.city_choices);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(getResources().getString(R.string.widget_dialog_chooser_title));
builder.setPositiveButton(getResources().getString(R.string.widget_dialog_chooser_posBtn), this);
builder.setNegativeButton(getResources().getString(R.string.widget_dialog_chooser_negBtn), this);
builder.setSingleChoiceItems(choices, -1, this);
return builder.create();
}


@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
//doing magic tricks
break;

case DialogInterface.BUTTON_NEGATIVE:
dialog.dismiss();
break;

default:
//more magic
break;
}
}
}

目前,背景是全黑的。我在这里做错了什么?

马库斯

最佳答案

将以下行添加到您的 onCreateDialog

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color
.TRANSPARENT));
return dialog;
}

关于Android透明DialogFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26156182/

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