美文网首页
【Android】底部BottomSheetDialogFrag

【Android】底部BottomSheetDialogFrag

作者: 下雨天的小白鞋 | 来源:发表于2019-06-24 11:27 被阅读0次

代码

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>

相关文章

网友评论

      本文标题:【Android】底部BottomSheetDialogFrag

      本文链接:https://www.haomeiwen.com/subject/fuhnqctx.html