广告
返回顶部
首页 > 资讯 > 精选 >在Android开发中使用WindowManager实现一个悬浮按钮
  • 565
分享到

在Android开发中使用WindowManager实现一个悬浮按钮

androidwindowmanagerage 2023-05-31 14:05:59 565人浏览 独家记忆
摘要

这篇文章将为大家详细讲解有关在Android开发中使用WindowManager实现一个悬浮按钮,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。效果:整体思路360手机卫士的内存球其实就是一个

这篇文章将为大家详细讲解有关在Android开发中使用WindowManager实现一个悬浮按钮,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

效果:

在Android开发中使用WindowManager实现一个悬浮按钮

整体思路

360手机卫士的内存球其实就是一个没有画面的应用程序,整个应用程序的主体是一个Service。我们的程序开始以后,启动一个service,同时关闭activity即可:

public class MainActivity extends Activity {  private static final String TAG = MainActivity.class.getSimpleName();  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    startService(new Intent(this, Floatwindowservice.class));    finish();  }}import android.os.IBinder;import android.util.Log;import java.util.Timer;import java.util.TimerTask;public class FloatWindowService extends Service {  private static final String TAG = FloatWindowService.class.getSimpleName();  public FloatWindowService() {  }  @Override  public int onStartCommand(Intent intent, int flags, int startId) {    Log.d(TAG, "on start command");    FloatWindowManager.instance(getApplicationContext()).createFloatWindow();    return super.onStartCommand(intent, flags, startId);  }  @Override  public IBinder onBind(Intent intent) {    // TODO: Return the communication channel to the service.    throw new UnsupportedOperationException("Not yet implemented");  }}

--结束END--

本文标题: 在Android开发中使用WindowManager实现一个悬浮按钮

本文链接: https://www.lsjlt.com/news/226086.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作