这篇文章将为大家详细讲解有关在Android开发中使用WindowManager实现一个悬浮按钮,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。效果:整体思路360手机卫士的内存球其实就是一个
这篇文章将为大家详细讲解有关在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文档到电脑,方便收藏和打印~
2024-04-27
2024-04-27
2024-04-27
2024-04-27
2024-04-27
2024-04-27
2024-04-27
2024-04-27
2024-04-27
2024-04-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0