Customization Bottom Sheet Dialog's View
I just want to get the BottomSheetDialog like below: margin from the system window. How can I get like this?
Solution 1:
You can create Bottom Sheet Dialog Fragment in following way:
First create the xml file as below named as
fragment_bottomsheet
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@android:color/transparent"android:orientation="vertical"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="@dimen/_150sdp"android:layout_margin="@dimen/_20sdp"android:background="@drawable/round_corner_white3"android:orientation="vertical"><TextViewandroid:id="@+id/tv_select_address"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:textColor="@color/white"android:background="@drawable/round_corner_gray"android:layout_margin="@dimen/_10sdp"android:layout_alignParentBottom="true"android:paddingBottom="@dimen/_10sdp"android:paddingTop="@dimen/_10sdp"android:text="Select Address" /></RelativeLayout></RelativeLayout>
Now create a Bottom Sheet Fragment named as
BottomSheetFragment
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.view.View;
publicclassBottomSheetFragmentextendsBottomSheetDialogFragment {
publicstatic BottomSheetFragment newInstance() {
BottomSheetFragmentfragment=newBottomSheetFragment();
return fragment;
}
@OverridepublicvoidonCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@OverridepublicvoidsetupDialog(Dialog dialog, int style) {
ViewcontentView= View.inflate(getContext(), R.layout.fragment_bottomsheet, null);
dialog.setContentView(contentView);
((View) contentView.getParent()).setBackgroundColor(getResources().getColor(android.R.color.transparent));
}
}
To call that bottom sheet fragment you can write as below:
BottomSheetFragmentbottomSheetDialog= BottomSheetFragment.newInstance();
bottomSheetDialog.show(getSupportFragmentManager(), "Bottom Sheet Dialog Fragment");
I have only took a single textview for now and attaching the screenshot because your main concern is to get margin in bottomsheet. Also in this way you can customize bottom sheet as you want. Thanks!
Solution 2:
Add Dependency
implementation 'com.baoyz.actionsheet:library:1.1.7'
Add this code in Activity
publicvoidButtonActionSheet() {
ActionSheet.createBuilder(this, getSupportFragmentManager())
.setCancelButtonTitle("Cancel")
.setOtherButtonTitles("item1", "item2")
.setCancelableOnTouchOutside(true)
.setListener(newActionSheet.ActionSheetListener() {
@OverridepublicvoidonDismiss(ActionSheet actionSheet, boolean isCancel) {
}
@OverridepublicvoidonOtherButtonClick(ActionSheet actionSheet, int index) {
if (index == 0) {
myMethod();
} elseif (index == 1) {
myMethod2();
}
}
})
.show();
}
Add this line in style.xml
<itemname="actionSheetStyle">@style/ActionSheetStyleiOS7</item>
Post a Comment for "Customization Bottom Sheet Dialog's View"