Android Xpopup 使用日记

正经人也写使用日记


使用步骤,引入依赖

implementation 'com.lxj:xpopup:2.2.8'

1.自定义

  没什么比自定义更重要

论  "一个弹窗可能需要单独设置的地方"

 

全局性设置

全局设置推荐在Application中进行设置。

  1. 1设置主色调 默认情况下,XPopup的主色为灰色,主色作用于Button文字,EditText边框和光标,Check文字的颜色上。 主色调只需要设置一次即可,可以放在Application中设置。
XPopup.setPrimaryColor(getResources().getColor(R.color.colorPrimary));
  1. 2设置全局的动画时长 默认情况下,弹窗的动画时长为360毫秒。你可以通过下面的方法进行修改:
XPopup.setAnimationDuration(200); // 传入的时长最小为0,动画的时长会影响除Drawer弹窗外的所有弹窗
  1. 3设置弹窗的半透明背景色值
XPopup.setShadowBgColor(xxx);


自定义一个弹窗

https://github.com/li-xiaojun/XPopup/wiki/3.-%E8%87%AA%E5%AE%9A%E4%B9%89%E5%BC%B9%E7%AA%97

 

 

全屏

关于状态栏之类的也都有设置的

basePopupView = new XPopup.Builder(context)
                .popupAnimation(PopupAnimation.NoAnimation)  //设置动画
                .dismissOnTouchOutside(false)  // 点击外面不消失
                .hasShadowBg(false)
                .asCustom(new FullScreenPopupView(context) {
                    // 返回自定义弹窗的布局
                    @Override
                    protected int getImplLayoutId() {
                        return R.layout.dialog_net_loading;
                    }
                });

 

2.

new XPopup.Builder(MainActivity.this)
                        .popupAnimation(PopupAnimation.TranslateAlphaFromBottom)  //设置动画
                        .dismissOnTouchOutside(false)  // 点击外面不消失
                        .atView(v)
                        .asCustom(new CenterPopupView(MainActivity.this) {

                            private View title;
                            private MyAdapter myAdapter;
                            private List<String> list;


                            @Override
                            protected int getImplLayoutId() {
                                return R.layout.custom_popup;
                            }

                            @Override
                            protected void onCreate() {
                                super.onCreate();

                                title = findViewById(R.id.title);
                                title.setOnClickListener(new OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        title.setVisibility(View.GONE);
                                    }
                                });

                                list = new ArrayList<String>() {
                                    {
                                        for (int i = 0; i < 10; i++) {
                                            add("" + i);
                                        }
                                    }
                                };
                                myAdapter = new MyAdapter(R.layout.item_text, list);
                                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this);

                                RecyclerView rv = findViewById(R.id.rv);
                                rv.setAdapter(myAdapter);
                                rv.setLayoutManager(linearLayoutManager);

                                myAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                                    @Override
                                    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                                        ToastUtils.showShort(position + "");
                                        myAdapter.remove(position);
                                    }
                                });

                            }
                        })
                        .show();

如果一开始的list你设定高度

加一行

                            @Override
                            protected int getMaxHeight() {
                                return ConvertUtils.dp2px(200);
                            }

注意 使用BottomPop 的时候要设置 enabledrag

 

普通使用

new XPopup.Builder(mContext)
                .popupAnimation(PopupAnimation.TranslateAlphaFromBottom)  //设置动画
                .dismissOnTouchOutside(true)  // 点击外面消失
                .maxWidth(ScreenUtils.getScreenWidth())
                .enableDrag(false)
                .asCustom(new BottomPopupView(mContext) {
                    @Override
                    protected int getImplLayoutId() {
                        return R.layout.popup_jibiji_update;
                    }

                    @Override
                    protected void onCreate() {
                        PopupJibijiTuichuBinding bind = DataBindingUtil.bind(getPopupImplView());

                    }
                }).show();

自定义动画

 new XPopup.Builder(getContext())
                                .customAnimator(new PopupAnimator() {
                                    @Override
                                    public void initAnimator() {

                                    }

                                    @Override
                                    public void animateShow() {
                                        AnimatorSet animatorSet = new AnimatorSet();
                                        animatorSet.playTogether(//
                                                ObjectAnimator.ofFloat(targetView, "alpha", 1, 1, 1, 1, 1, 1, 1, 1),//
                                                ObjectAnimator.ofFloat(targetView, "rotation", 0, 10, -10, 6, -6, 3, -3, 0));
                                        animatorSet.setDuration(1000);
                                        animatorSet.start();
                                    }

                                    @Override
                                    public void animateDismiss() {

                                    }
                                })
                                .popupAnimation(PopupAnimation.NoAnimation)  //设置动画
                                .dismissOnTouchOutside(true)  // 点击外面不消失
                                .hasShadowBg(true)
                                .asCustom(new CenterPopupView(getContext()) {
                                    // 返回自定义弹窗的布局
                                    @Override
                                    protected int getImplLayoutId() {
                                        return R.layout.dialog_erweima;
                                    }

                                    @Override
                                    protected int getPopupWidth() {
                                        return (int) (ScreenUtils.getScreenWidth() * 0.85f);
                                    }


                                }).show();

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值