Android动态壁纸 Live Wallpaper

                                                                                                                  动态壁纸Live Wallpaper架构

 

组件类

说明

WallpaperService

实现动态壁纸的服务程序

WallpaperService.Engine

描绘动态壁纸的引擎

PreferenceActivity

动态壁纸的参数设置窗体

 

动态壁纸Live Wallpaper应用程序必须实现动态壁纸的服务程序WallpaperService和描绘动态壁纸的引擎WallpaperService.Engine,当你需要设置动态壁纸的参数来改变动画的属性时,必须提供设置参数的窗体。此时才需要实现动态壁纸的参数设置窗体PreferenceActivity

咱们先来说一次简单的步骤:

(1)建一个类继承WallpaperService,比如说为LiveWallpaper.java

(2)然后在AndrodManifest.XML文件的<service>标签内定义动态壁纸的服务程序LiveWallpaper.java和动态壁纸的资源来源“/res/XML/liveWallpaper.XML”

(3)还需要增加一个<Activity>标签来设置动态壁纸参数设置程序HelloLiveWallpaperSetting.java,当然这个要去继承PreferenceActivity

AndrodManifest.XML

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.njue.livewallpaper"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
            <service
         android:label="@string/app_name"
         android:permission="android.permission.BIND_WALLPAPER" 
         android:name=".LiveWallpaper">
         <intent-filter>
             <action android:name="android.service.wallpaper.WallpaperService" />
         </intent-filter>
         <meta-data android:name="android.service.wallpaper" 
         			android:resource="@xml/livewallpaper" />            
       </service>
       	<activity android:name=".LiveWallpaperSettings" 
		android:label="@string/wallpaper_settings" 
		android:theme="@android:style/Theme.Light.WallpaperSettings"
		android:exported="true">
	</activity>
    </application>
</manifest>


 

/res/XML/liveWallpaper.XML

<?xml version="1.0" encoding="UTF-8"?>
<wallpaper 
    xmlns:android="http://schemas.android.com/apk/res/android"  
    android:thumbnail="@drawable/floewr1" 
    android:description="@string/description"
    android:settingsActivity="com.njue.livewallpaper.LiveWallpaperSettings"
    />

参数设置界面的布局代码settings.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:title="@string/settings">
  <ListPreference
      android:key="@string/leaf1Count"
      android:title="@string/settings_title"
      android:summary="@string/settings_summary"
      android:entries="@array/entries"
      android:entryValues="@array/values" />
        <ListPreference
      android:key="@string/flower1Count"
      android:title="@string/settings_title1"
      android:summary="@string/settings_summary1"
      android:entries="@array/entries"
      android:entryValues="@array/values" />
        <ListPreference
      android:key="@string/flower2Count"
      android:title="@string/settings_title2"
      android:summary="@string/settings_summary2"
      android:entries="@array/entries"
      android:entryValues="@array/values" />
    <EditTextPreference
   android:key="@string/inputText"
   android:title="输入你喜欢的文字"
   android:summary="点击输入"
   android:dialogTitle="输入文字设置"
   
     />
        <EditTextPreference
   android:key="@string/wordCount"
   android:title="一列显示的字符数"
   android:summary="请输入数字"
   android:dialogTitle="一列显示的字符数(请输入数字)"
   android:digits="0123456789" 
   />
   <PreferenceCategory
   android:title="恢复默认设置"
   >
   <CheckBoxPreference
   android:key="@string/reset"
   android:title="恢复默认设置"
   android:summaryOn="恢复默认设置"
   android:summaryOff="恢复默认设置"
   android:defaultValue="false"
   ></CheckBoxPreference>
   </PreferenceCategory>  

</PreferenceScreen>


 

这是一个我自己编写的简单动态壁纸效果图:

 

想了解具体实现细节的同学,可以下载本文工程。

下载地址:http://download.csdn.net/detail/pzhtpf/4266265


 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值