代码
public class CustomFragment entextends BottomSheetDialogFragmentimplements View.OnClickListener {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置背景透明,才能显示出layout中诸如圆角的布局,否则会有白色底(框)
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme);
@Nullable
@Override
public ViewonCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.bottom_add_dynamic, container, false);
RelativeLayout rlFirst= view.findViewById(R.id.rl_1);
RelativeLayout rlSecond= view.findViewById(R.id.rl_2);
rlFirst.setOnClickListener(this);
rlSecond.setOnClickListener(this);
return view;
}
@Override
public void onClick(View v) {
if (getTargetFragment() ==null) {
return;
}
switch (v.getId()) {
case R.id.rl_1:
Intent intent =new Intent();
intent.putExtra(Constants.TYPE, Constants.type_short);
getTargetFragment().onActivityResult(CommunityTabRecommandFragment.NEW_DYNAMIC_CODE, Activity.RESULT_OK, intent);
break;
case R.id.rl_2:
intent =new Intent();
intent.putExtra(Constants.TYPE, Constants.type_long_story);
getTargetFragment().onActivityResult(CommunityTabRecommandFragment.NEW_DYNAMIC_CODE, Activity.RESULT_OK, intent);
break;
}
}
}
style
<style name="CustomBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/CustomBottomSheetStyle
<style name="CustomBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@android:color/transparent
</style>