美文网首页
Android PopupWindow

Android PopupWindow

作者: 潜心之力 | 来源:发表于2018-08-13 14:27 被阅读0次

    显示PopupWindow

        private void showShareWindow(Context context) {
            LayoutInflater inflater = LayoutInflater.from(context);
            View child = inflater.inflate(R.layout.pop_comment_share, null);
            PopupWindow window = new PopupWindow(child, ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT, true);
            AutoUtils.autoSize(child);
            RelativeLayout parent = findViewById(R.id.act_comment_rl);
            window.setBackgroundDrawable(new BitmapDrawable());
            window.setOutsideTouchable(true);
            window.setFocusable(true);
            window.setAnimationStyle(R.style.CommentShareWindowTheme);
            window.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
            setBackGroundAlpha(0.3f);
            window.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    setBackGroundAlpha(1f);
                }
            });
        }
    

    设置弹窗外的背景颜色

        private void setBackGroundAlpha(float alpha) {
            WindowManager.LayoutParams params = getWindow().getAttributes();
            params.alpha = alpha;
            getWindow().setAttributes(params);
        }
    

    弹窗进入和退出的动画

        <style name="CommentShareWindowTheme" parent="AppTheme">
            <!-- 指定显示的动画xml -->
            <item name="android:windowEnterAnimation">@anim/act_bottom_in</item>
            <!-- 指定消失的动画xml -->
            <item name="android:windowExitAnimation">@anim/act_bottom_out</item>
        </style>
    

    进入动画

    <?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="200"
        android:fillAfter="true"
        android:fromYDelta="100%"
        android:toYDelta="0" />
    

    退出动画

    <?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="200"
        android:fromYDelta="0"
        android:toYDelta="100%"
        android:fillAfter="true"/>
    

    相关文章

      网友评论

          本文标题:Android PopupWindow

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