Android简单实现PopupWindow

第一步写个PopupWindow.xml弹出你想要的布局

第二步请看以下代码

        //设置contentView
        View contentView = LayoutInflater.from(this).inflate(R.layout.PopupWindow, null);
        //设置窗口显示大小
        PopupWindow mPopWindow = new PopupWindow(contentView, 900, 900, true);
        //将布局设置上去
        mPopWindow.setContentView(contentView);
        //默认为true,写不写都一样都是当点击popwindow以外的地方关闭窗口,写成false则相反
        //mPopWindow.setTouchable(false);
        View rootview = LayoutInflater.from(MainActivity.this).inflate(R.layout.activity_main, null);
        //显示的位置,现在是界面的中间
        mPopWindow.showAtLocation(rootview, Gravity.CENTER, 0, 0);

以上代码就是最基本的弹出一个PopupWindow窗口

猜你喜欢

转载自blog.csdn.net/weixin_42744183/article/details/90200250