`

LibGDX制作android动态壁纸

阅读更多

一、还是像普通的android动态壁纸一样,创建一个没有activity的安卓工程TestLibGDXWallpaper
二、AndroidManifest.xml配置

  1.     <application
  2.         android:icon="@drawable/icon"
  3.         android:label="@string/app_name" >
  4.         <service
  5.             android:name=".MyLiveWallpaper"
  6.             android:icon="@drawable/icon"
  7.             android:label="@string/app_name"
  8.             android:permission="android.permission.BIND_WALLPAPER" >
  9.             <intent-filter>
  10.                 <action android:name="android.service.wallpaper.WallpaperService" />
  11.             </intent-filter>
  12.             <meta-data
  13.                 android:name="android.service.wallpaper"
  14.                 android:resource="@xml/livewallpaper" />
  15.         </service>
  16.     </application>
复制代码

1、权限android:permission="android.permission.BIND_WALLPAPER",否则该壁纸只能预览,不能被实际应用
2、
添加声明android:name="android.service.wallpaper.WallpaperService"以便系统识别
3、android:name=".MyLiveWallpaper"为动态壁纸的service类
4、meta-data部分为动态壁纸的配置信息xml/livewallpaper需要手动创建res/xml/livewallpaper.xml


三 、livewallpaper.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:thumbnail="@drawable/icon" />
复制代码

只是配置其图标(没有“设置”项)


四、jar包和.so库导入
将从官方下载下来的压缩包中的gdx.jar和gdx-backend-android.jar包复制到工程libs目录下(再build path 步骤省略),将相关.so库复制到libs目录下!
 



五、service实现
1、service类MyLiveWallpaper实现gdx-backend-android中的AndroidLiveWallpaperService,这将需要实现三个抽象方法createConfig、createListener,这两个方法将会在壁纸出现时被调用(预览和点击设置之后都会调用);offsetChange,动态壁纸屏幕偏移量改变时调用!
2、createConfig直接返回new AndroidApplicationConfiguration();
3、createListener返回自写的类MyApplicationListener(实现ApplicationListener);
4、offsetChange可保存一些需要的偏移量。


至此一个动态壁纸的整体模版就出来了,可以设置为动态壁纸了,只是这个动态壁纸还没有内容罢了!
 

看到黑乎乎的动态壁纸却不知道怎么给其加上view,那么主要的问题就是在哪里添加view,就像普通的动态壁纸,显然添加不会放在service,那么就只能放在applicationListener咯
而applicationListener正是之前做桌面特效的粒子监听,于是将其搬移至此,测试可用!
 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics