栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Android悬浮窗功能

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android悬浮窗功能

 如果每个界面都要显示悬浮窗,则把这段代码写在baseActivity即可,如果只是在某个界面显示,直接在该Activity写就可以了,或是直接在布局xml文件写。
frameLayout rootView = (frameLayout) getWindow().getDecorView();
        frameLayout.LayoutParams textParams = new frameLayout.LayoutParams(frameLayout.LayoutParams.WRAP_CONTENT, frameLayout.LayoutParams.WRAP_CONTENT);
        textParams.gravity = Gravity.RIGHT | Gravity.BOTTOM;
        textParams.bottomMargin = DensityUtils.dp2px(this, 60);
        textParams.rightMargin = DensityUtils.dp2px(this, 5);
        FloatingActionButton actionButton = new FloatingActionButton(this);
        actionButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.icon_float_view));
        ColorStateList colorStateList = ContextCompat.getColorStateList(this, R.color.color999999);
        actionButton.setBackgroundTintMode(PorterDuff.Mode.SRC_ATOP);
        actionButton.setBackgroundTintList(colorStateList);
        actionButton.setLayoutParams(textParams);
        actionButton.setonClickListener(v -> {
            ToastUtils.showShort("我是悬浮窗");
        });

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/273900.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号