BottomSheetDialog with transparent background
So, I figured out 2 solutions.
Best one:
Create an activity with transparent background just for your bottom sheet.
Implement your own layout with a coordinator layout and a bottom sheet.
Set the margin you want.
Set the content you want.
Not tested yet.
Lazy one:
Extends BottomSheetDialogFragment, in onActivityCreated
add:
Resources resources = getResources();
// Set margin for Landscape Mode. Maybe a more elegant solution will be to implements our own bottom sheet with our own margins.
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
assert getView() != null;
View parent = (View) getView().getParent();
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) parent.getLayoutParams();
layoutParams.setMargins(
resources.getDimensionPixelSize(R.dimen.bottom_sheet_margin_left), // 64dp
0,
resources.getDimensionPixelSize(R.dimen.bottom_sheet_margin_right), // 64dp
0
);
parent.setLayoutParams(layoutParams);
}
Android bottomsheet dialog tansparent background
Maybe you should also set your Dialog Window to transparent.
add the following code to your BottomSheetDialog.
// BottomSheetDialog
public BottomSheetDialog(Context context) {
super(context, R.style.Bottom_Sheet_Style); //set your own dialog theme
// ...
Window window = getWindow();
window.setBackgroundDrawableResource(android.R.color.transparent);
WindowManager.LayoutParams lp = window.getAttributes();
lp.alpha = 1.0f;
lp.dimAmount = 0.0f;
window.setAttributes(lp);
// ...
}
Then add the following code to your res/values/styles.xml. If you don't have the file, then create one.
<style name="Bottom_Sheet_Style" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
Remove White Background in Bottom Sheet Dialog Fragment
You will need to set transparent background to bottom sheet view itself.
Here is an example is 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)
}
}
Related Topics
How Do Popular Apps Authenticate User Requests from Their Mobile App to Their Server
Android - Choose File Button in Webview
Android: Save File Permanently (Even After Clear Data/Uninstall)
Is There a Faster Way to Decode HTML Characters to a String Than HTML.Fromhtml()
How to Set The Title Color for The New Toolbar
How to Get Preview in Composable Functions That Depend on a View Model
Get Meta Data of Image - Android
Running Google Map Application on Android Emulator
How to Style Appcompat-V7 Toolbar Like Theme.Appcompat.Light.Darkactionbar
JSONarray Cannot Be Converted to JSONobject Error
Use of Context to Start Another Activity
Finding Android Sdk on MAC and Adding to Path
Which HTML Tags Are Supported by Android Textview
How to Put Recyclerview Inside Nestedscrollview
HTML5 <Video> Element on Android Does Not Play
Change Fill Color on Vector Asset in Android Studio
Android: Keyboard Overlaps with the Edittext (With Printscreens)