gpt4 book ai didi

android - 删除底部工作表对话框 fragment 中的白色背景

转载 作者:行者123 更新时间:2023-12-01 11:15:45 26 4
gpt4 key购买 nike

如何删除底部工作表对话框 fragment 中的白色背景?

我已经尝试了 this 中的答案或将布局xml中的背景设置为透明,但仍然得到这个结果

enter image description here

这是我的代码

public class BottomSheetFragment extends BottomSheetDialogFragment {

private Record record;

private MainFragment fragment;

public static BottomSheetFragment getInstance() {
return new BottomSheetFragment ();
}

public BottomSheetFragment setRecord(Record record) {
this.record = record;
return this;
}

public BottomSheetFragment setFragment(MainFragment fragment) {
this.fragment = fragment;
return this;
}

@TargetApi(Build.VERSION_CODES.O)
@Override
public void onViewCreated(View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT);
setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme);

//Set content
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.layout_bottom_sheet, container);
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}

layout_bottom_sheet.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="60dp"
android:background="@drawable/bg_cardboard">

</FrameLayout>

最佳答案

您需要将透明背景设置为底部工作 TableView 本身。

下面是 Kotlin 的一个例子:

class YourBottomSheetFragment : BaseBottomSheetDialogFragment() {

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
dialog.setOnShowListener { setupBottomSheet(it) }
return dialog
}

private fun setupBottomSheet(dialogInterface: DialogInterface) {
val bottomSheetDialog = dialogInterface as BottomSheetDialog
val bottomSheet = bottomSheetDialog.findViewById<View>(
com.google.android.material.R.id.design_bottom_sheet)
?: return
bottomSheet.setBackgroundColor(Color.TRANSPARENT)
}
}

关于android - 删除底部工作表对话框 fragment 中的白色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51610722/

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