Android 如何使用底部重力和alpha背景创建警报对话框?

Android 如何使用底部重力和alpha背景创建警报对话框?,android,android-studio,android-layout,android-alertdialog,Android,Android Studio,Android Layout,Android Alertdialog,我正在使用alert dialog在android应用程序中创建一个对话框。我有一个问题。它的背景是全白色的。我希望对话框窗口的背景为alpha(半透明),如图所示。请帮帮我。 有两种方法可以实现这一点 BottomSheetDialog BottomSheetDialogFragment e、 g fragment_bottom_sheet_dialog.xml <LinearLayout android:layout_width="match_pa

我正在使用alert dialog在android应用程序中创建一个对话框。我有一个问题。它的背景是全白色的。我希望对话框窗口的背景为alpha(半透明),如图所示。请帮帮我。


有两种方法可以实现这一点

  • BottomSheetDialog
  • BottomSheetDialogFragment
  • e、 g fragment_bottom_sheet_dialog.xml

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/lorem_ipsum"/>
    
        </LinearLayout>
    
    现在,在activity/fragment中,这两个方法可以基于任何事件(如click事件)调用

    public void showBottomSheetDialog() {
        View view = getLayoutInflater().inflate(R.layout.fragment_bottom_sheet_dialog, null);
     
        BottomSheetDialog dialog = new BottomSheetDialog(this);
        dialog.setContentView(view);
        dialog.show();
    }
     
     
    /**
     * showing bottom sheet dialog fragment
     * same layout is used in both dialog and dialog fragment
     */
    
    public void showBottomSheetDialogFragment() {
        BottomSheetFragment bottomSheetFragment = new BottomSheetFragment();
        bottomSheetFragment.show(getSupportFragmentManager(), bottomSheetFragment.getTag());
    }
    

    有两种方法可以实现这一点

  • BottomSheetDialog
  • BottomSheetDialogFragment
  • e、 g fragment_bottom_sheet_dialog.xml

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/lorem_ipsum"/>
    
        </LinearLayout>
    
    现在,在activity/fragment中,这两个方法可以基于任何事件(如click事件)调用

    public void showBottomSheetDialog() {
        View view = getLayoutInflater().inflate(R.layout.fragment_bottom_sheet_dialog, null);
     
        BottomSheetDialog dialog = new BottomSheetDialog(this);
        dialog.setContentView(view);
        dialog.show();
    }
     
     
    /**
     * showing bottom sheet dialog fragment
     * same layout is used in both dialog and dialog fragment
     */
    
    public void showBottomSheetDialogFragment() {
        BottomSheetFragment bottomSheetFragment = new BottomSheetFragment();
        bottomSheetFragment.show(getSupportFragmentManager(), bottomSheetFragment.getTag());
    }
    

    尝试使用BottomSheet尝试使用BottomSheet如何应用圆角?它基于您的布局,您可以使用可绘制的背景矩形和上边缘角,并添加到对话框的父布局背景如何应用圆角?它基于您的布局,您可以使用带有上角的可绘制背景矩形,并将其添加到对话框的父布局背景中