android浮窗,android 悬浮窗实现

Android 浮窗按钮FloatActionButton

android.support.design.widget.CoordinatorLayout

站在用户的角度思考问题,与客户深入沟通,找到轮台网站设计与轮台网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站设计、成都网站制作、企业官网、英文网站、手机端网站、网站推广、域名与空间、虚拟空间、企业邮箱。业务覆盖轮台地区。

android:layout_width="match_parent"

android:layout_height="match_parent"

其他控件

android.support.design.widget.FloatingActionButton

android:id="@+id/pro_departmeng_fab"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@mipmap/pro_button"

android:onClick="onClick"

app:layout_anchor="@id/bc_pro_department"

app:layout_anchorGravity="right|top"

android:layout_marginRight="@dimen/size5"

app:rippleColor="@color/colorPrimary"

app:borderWidth="@dimen/size0"

android:elevation="@dimen/size5"

android:backgroundTint="@color/white"

app:fabSize="mini"/

//初始化

@Bind(R.id.pro_departmeng_fab)

FloatingActionButtonproDepartmengFab;

//监听事件

proDepartmengFab.setOnClickListener(newView.OnClickListener() {

@Override

public voidonClick(View view) {

Toast.makeText(getContext(),"test",Toast.LENGTH_LONG).show();

}

});

四、属性介绍

1、app:borderWidth=""------------------边框宽度,通常设置为0 ,用于解决Android 5.X设备上阴影无法正常显示的问题

2、app:backgroundTint=""---------------按钮的背景颜色,不设置,默认使用theme中colorAccent的颜色

3、app:rippleColor=""--------------------点击的边缘阴影颜色

4、app:elevation=""----------------------边缘阴影的宽度

5、app:pressedTranslationZ="16dp"-----点击按钮时,按钮边缘阴影的宽度,通常设置比elevation的数值大

android 系统级的悬浮窗实现

当我们在使用的app的时候,如果需要实时观测到某个功能的实时进度并且不影响其他的操作的时候或者不影响使用其他应用的时候,系统级的悬浮球是个非常不错的选择。

public class QueueUpFloatService extends Service {

/**

* 启动服务并传值

*

* @param activity 启动服务的activity

* @param modeBean 数据对象

*/

public static void launchService(Activity activity, ModeBean modeBean) {

try {

Intent intent =new Intent(activity, QueueUpFloatService.class);

    Bundle bundle =new Bundle();

    bundle.putSerializable(KEY_MODEL, modeBean);

    intent.putExtras(bundle);

    activity.startService(intent);

}catch (Exception e) {

e.printStackTrace();

}

}

@Override

public void onCreate() {

super.onCreate();

}

@Override

public IBinder onBind(Intent intent) {

return null;

}

@Override

public int onStartCommand(Intent intent, int flags, int startId) {

return super.onStartCommand(intent, flags, startId);

}

@Override

public void onDestroy() {

super.onDestroy();

}

}

@Override

public void onCreate() {

super.onCreate();

//加一点简单的动画 

buttonScale = (ScaleAnimation) AnimationUtils.loadAnimation(this, R.anim.anim_float);

windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

layoutParams =new WindowManager.LayoutParams();

if (Build.VERSION.SDK_INT = Build.VERSION_CODES.O) {

layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;

}else {

layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;

}

layoutParams.format = PixelFormat.RGBA_8888;

layoutParams.gravity = Gravity.LEFT | Gravity.TOP;

layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |             WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;

layoutParams.width = ScreenUtils.dp2px(66);

layoutParams.height = ScreenUtils.dp2px(66);

layoutParams.x = ScreenUtils.getRealWidth() - ScreenUtils.dp2px(60);

layoutParams.y = ScreenUtils.deviceHeight() *2 /3;

}

@Override

public int onStartCommand(Intent intent, int flags, int startId) {

ModeBean modeBean = (ModeBean) intent.getExtras().getSerializable(KEY_MODEL);

LayoutInflater layoutInflater = LayoutInflater.from(this);

floatView = layoutInflater.inflate(R.layout.view_float, null);

RelativeLayout rlFloatParent =floatView.findViewById(R.id.rl_float_parent);

rlFloatParent.startAnimation(buttonScale);

TextView tvIndex =floatView.findViewById(R.id.tv_queue_index);

tvIndex.setText(modeBean.title);

floatView.findViewById(R.id.iv_close_float).setOnClickListener(v - stopSelf());

//修改悬浮球的滑动实现

floatView.setOnTouchListener(new FloatingOnTouchListener());

windowManager.addView(floatView, layoutParams);

return super.onStartCommand(intent, flags, startId);

}

private class FloatingOnTouchListenerimplements View.OnTouchListener {

private int x;

private int y;

private long downTime;

@SuppressLint("ClickableViewAccessibility")

@Override

public boolean onTouch(View view, MotionEvent event) {

switch (event.getAction()) {

case MotionEvent.ACTION_DOWN:

downTime = System.currentTimeMillis();

                    x = (int) event.getRawX();

                    y = (int) event.getRawY();

break;

            case MotionEvent.ACTION_MOVE:

int nowX = (int) event.getRawX();

                    int nowY = (int) event.getRawY();

                    int movedX = nowX -x;

                    int movedY = nowY -y;

                    x = nowX;

                    y = nowY;

                    layoutParams.x =layoutParams.x + movedX;

                    layoutParams.y =layoutParams.y + movedY;

                    windowManager.updateViewLayout(view, layoutParams);

break;

            case MotionEvent.ACTION_UP:

/* *

* 这里根据手指按下和抬起的时间差来判断点击事件还是滑动事件

* */

                    if ((System.currentTimeMillis() -downTime) 200) {

                            //检测应用在前台还是后台

if (AppUtils.isAppIsInBackground()) {

AppUtils.moveToFront(CloseActivityUtils.activityList.get(CloseActivityUtils.activityList.size() -1).getClass());

                            } else {

                                    //检测栈顶是否为SecondActivity 不是就打开SecondActivity

                                  if (!CloseActivityUtils.activityList.get(CloseActivityUtils.activityList.size() -1)

                                            .getClass().getSimpleName().contains("SecondActivity")) {

                                    SecondActivity.launchActivity(CloseActivityUtils.activityList.get(CloseActivityUtils.activityList.size() -1));

                            }

                  }

}

break;

        default:

break;

    }

   return false;

}

}

@Override

public void onDestroy() {

super.onDestroy();

if (null ==floatView) {

return;

           }

windowManager.removeView(floatView);

        windowManager=null;

}

flutter android 原生浮窗组件 android_window 介绍

仓库地址:

pub 地址:

修改 MainActivity.kt 让 MainActivity 继承 qiuxiang.android_window.AndroidWindowActivity :

创建 MainApplication.kt :

修改 AndroidManifest.xml 的 application 新增属性 android:name=".MainApplication" :

main.dart:

我们需要用 @pragma('vm:entry-point') 声明一个入口函数,默认函数名是 androidWindow ,当然你可以随意指定一个,只是调用 open 的时候需要同时指定参数 entryPoint: 。

android_window.dart:

浮窗 app 的写法就和我们平时写的 app 没什么区别了,如果需要支持窗口拖拽移动,则要在最外层使用 AndroidWindow 。

最终效果:

更完整的示例请参考:

主应用和浮窗都有 post 和 setHandler 方法用于发送消息以及设置监听处理函数。用法举例:

主应用发送消息到浮窗:

浮窗监听并处理主应用消息:

反过来同理。

Android视频悬浮窗口实现

本文例子实现了点击显示悬浮窗口,同时窗口可播放视频,拖动位置,点击关闭及返回 APP 页面,通过例子来讲述悬浮窗口实现原理及细节处理,效果图如下所示:

关于悬浮窗的一些基本操作到这里就基本结束了,具体的布局内容及操作,欢迎查看具体的源码实现: Github开发记录

欢迎点击查阅及Star,我也会继续补充其它有用的知识及例子在项目上。

欢迎点赞/评论,你们的赞同和鼓励是我写作的最大动力!

android 微信小程序支付 开启显示悬浮窗 权限

1、首先打开微信软件app。

2、进去后主页后找到右下角的我的。

3、然后点击一下。

4、进去我的以后找到设置并点击进去。

5、找到显示悬浮窗点击一下并选择小程序支付就开启显示悬浮窗了。


本文题目:android浮窗,android 悬浮窗实现
链接URL:http://ybzwz.com/article/dsespjs.html