我正在创建一个DialogFragment来显示有关我的应用程序的一些帮助消息.一切工作正常,除了一两件事:有一个在,显示DialogFragment窗口顶部的黑色条纹,那我相信是留给冠军,这是我不想用.
这是特别痛苦的,因为我的自定义DialogFragment使用白色背景,所以这种变化太臭名昭着,不能放在一边.
让我以更加图形化的方式向您展示:

现在我的DialogFragment的XML代码如下:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/holding"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/dialog_fragment_bg"
>
<!-- Usamos un LinearLayout para que la imagen y el texto esten bien alineados -->
<LinearLayout
android:id="@+id/confirmationToast"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView android:id="@+id/confirmationToastText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="@string/help_dialog_fragment"
android:textColor="#AE0000"
android:gravity="center_vertical"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/confirmationButtonLL"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
>
<Button android:id="@+id/confirmationDialogButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="60dp"
android:background="@drawable/ok_button">
</Button>
</LinearLayout>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
以及实现DialogFragment的类的代码:
public class HelpDialog extends DialogFragment {
public HelpDialog() {
// Empty constructor required for DialogFragment
} …Run Code Online (Sandbox Code Playgroud) 如何删除底部工作表对话框片段中的白色背景?
我试图在回答这个或设置在布局XML透明背景,但仍得到这样的结果
这是我的代码
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 …Run Code Online (Sandbox Code Playgroud) 我有一个对话片段,看起来像那样.

AlertDialog ad = builder.create();
Drawable d = new ColorDrawable(Color.BLACK);
d.setAlpha(130);
ad.getWindow().setBackgroundDrawable(d);
Run Code Online (Sandbox Code Playgroud)
此代码使背景半透明.但我仍然在底部有一个白色的部分.我想摆脱白色只有半透明背景
我已经尝试了很多我在其他帖子中看到过的东西.
我不知道我必须在DialogFragment,AlertDialog和LinearLayout之间改变什么对象.
它可能不是LinearLayout,因为当我增加边距时,没有任何东西在移动.
这是我的代码:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// setStyle(DialogFragment.STYLE_NORMAL, 0);
// setStyle(STYLE_NO_FRAME, R.style.CustomDialog);
// setStyle(STYLE_NO_FRAME, 0);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(
R.layout.share_or_die, null);
AlertDialog ad = builder.create();
Drawable d = new ColorDrawable(Color.BLACK);
d.setAlpha(130);
ad.getWindow().setBackgroundDrawable(d);
ad.setCanceledOnTouchOutside(true);
ad.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
ad.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
return ad;
}
Run Code Online (Sandbox Code Playgroud)
我只是在用户单击后退按钮时在mainActivity中调用它:
@Override
public void onBackPressed() {
if (isUserConnected && !hasShared) {
shareOnExitDialog = new ShareOnExitDialog();
shareOnExitDialog.setCancelable(true);
shareOnExitDialog.show(getSupportFragmentManager(), "Exit");
} …Run Code Online (Sandbox Code Playgroud)