BottomSheetDialogFragment的使用很简单
public class CustomBottomSheetDialogFragment extends BottomSheetDialogFragment implements View.OnClickListener
{
@Override
public void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.spec_bottom_sheet, container, false);
return rootView;
}
}
但是默认的布局后面有个白色的背景,不符合需求,需要去掉外层默认的白色背景
设置Dialog主题即可
@Override
public void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//设置背景透明,才能显示出layout中诸如圆角的布局,否则会有白色底(框)
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme);
}
<style name="CustomBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/CustomBottomSheetStyle</item>
</style>
<style name="CustomBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@android:color/transparent</item>
</style>