Transparent BottomSheet Dialog with radius
Hello viewers today in this topic I'll show to you about using Transparent BottomSheet dialog with stylish radius
1.Go to Sketchware and create a new project, Enable App Compact & Design from Library manager
2. Add a button to show this dialog
3. Go to custom view and create a custom view named "cust" & design your dialog there, add a linear (Linear1) and a button for close the dialog, set linear margin to (10)
4. Now go to event on button clicked and set this codes to create custom dialog
Code:final com.google.android.material.bottomsheet.BottomSheetDialog dialog = new com.google.android.material.bottomsheet.BottomSheetDialog(MainActivity.this);
View lay = getLayoutInflater().inflate(R.layout.cust, null);
dialog.setContentView(lay);
5. Find your widget id from custom view
final LinearLayout linear = (LinearLayout)lay.findViewById(R.id.linear1);
final Button close = (Button)lay.findViewById(R.id.button1);
6. Set the custom background to Transparent with this code
dialog.getWindow().findViewById(R.id.design_bottom_sheet).setBackgroundResource(android.R.color.transparent);
dialog.show();
7. Now set this radius of main linear
Code:android.graphics.drawable.GradientDrawable wd = new android.graphics.drawable.GradientDrawable();
wd.setColor(Color.WHITE);
wd.setCornerRadius((int)10f);
linear.setBackground(wd);
8. Now hide dialog on button click listener
Code:close.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
//your work here
//now close this work & dismiss the dialog
dialog.dismiss();
}});
Like this
9. Save & run your project, this BottomSheet dialog will look like this.
Thanks for visiting
Cool!
ReplyDelete