Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make the corners of my bottom sheet dialog rounded?

I'm trying to make the top corners of my BottomSheetDialog rounded, but I haven't had any luck with anything online. This is what I would like for it to look like:

Rounded Modal Bottom Sheet

No matter what I've tried, I keep getting this:

Not rounded Modal Bottom Sheet

I've tried the method here and using shapeAppearanceLargeComponent (what I'm using now).

Here is my code:

styles.xml

 <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    ...
    <item name="shapeAppearanceLargeComponent">@style/CustomShapeAppearanceBottomSheetDialog</item>
</style>

<style name="CustomShapeAppearanceBottomSheetDialog" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSizeTopRight">16dp</item>
    <item name="cornerSizeTopLeft">16dp</item>
</style>

BottomNavMenuFragment:

public class BottomNavMenuFragment extends BottomSheetDialogFragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_bottom_nav_drawer, container, false);
    }
}

And this is how I'm showing the fragment:

BottomNavMenuFragment navFragment = new BottomNavMenuFragment();
navFragment.show(getSupportFragmentManager(), navFragment.getTag());

Nothing I seem to do works. Could someone point me in the right direction?

like image 490
Spencer Beaumont Avatar asked May 30 '20 08:05

Spencer Beaumont


People also ask

How to make custom dialog with rounded corners in Android?

This example demonstrate about How to make custom dialog with rounded corners in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken button.

How to make bottom sheet dialog top round in Android?

FrameLayout bottomSheet ; This one defined in setDialogBorder () method. This actually is the default view for the bottom sheet dialog in android. It will work fine. You have to change the bottom sheet theme to achieve the top round layout Create a custom drawable background_bottom_sheet_dialog_fragment.xml:

How do I choose the right shape for my bottom sheet?

The first step in creating the right shape for your bottom sheet is to define a shape appearance. This is simply a style that defines what kind of shape we want for our bottom sheet. A simple rounded corner shape would look something like this: We could also create a shape with a cut off top left corner like this:

How to make a round corner bottom sheet in R?

open class CustomRoundBottomSheet : BottomSheetDialogFragment () { override fun getTheme (): Int = R.style.BottomSheetDialogTheme override fun onCreateDialog (savedInstanceState: Bundle?): Dialog = BottomSheetDialog (requireContext (), theme) } Now use this class wherever you want to have round corner bottom sheet . eg


1 Answers

Follow the below steps to attain top rounded corner bottomsheet:

Step 1: Create drawable rounded_top_corners.xml file inside drawable folder

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/white"/>
    <corners android:topLeftRadius="8dp"
        android:topRightRadius="8dp"/>
</shape>

Step 2: Create below styles in styles.xml

 <style name="BottomSheetDialogStyle" parent="Theme.Design.Light.BottomSheetDialog">
        <item name="bottomSheetStyle">@style/bottomSheetBackground</item>
    </style>

    <style name="bottomSheetBackground" parent="Widget.Design.BottomSheet.Modal">
        <item name="android:background">@drawable/rounded_top_corners</item>
    </style>

Step 3: Add style in BottomNavMenuFragment class

 @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(STYLE_NORMAL, R.style.BottomSheetDialogStyle);
    }

That's it, the style will be applied to bottomsheet.

like image 63
satuser Avatar answered Sep 21 '22 13:09

satuser