launcher5

来源:互联网 发布:超级玛丽for mac 编辑:程序博客网 时间:2024/06/05 04:17
显示壁纸


显示壁纸也是launcher必不可少的功能,下面我们看看如何让我们开发的launcher来显示壁纸。



新建一个叫做ShowWallpaper的工程,具体步骤略。

一. 显示壁纸
要在我们的activity里显示一个壁纸非常简单(包括动态壁纸也如此),我们只需要定义一个theme使其继承自android:Theme.Wallpaper,然后在activity中使用这个theme就ok了。
在res/valuse下面增加一个xml文件,其名称为styles.xml ,内容如下:
?
1
2
3
4
5
6
<resources>
<stylename="Theme"parent="android:Theme.Wallpaper">
<!-- windowNoTitle设置为true,去掉标题栏 -->
<itemname="android:windowNoTitle">true</item>
</style>
</resources>

此时整个工程的结果如下:



下面在AndroidManifest.xml中使用这个theme,如下图所示:



xml代码如下
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xmlversion="1.0"encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0">
<applicationandroid:icon="@drawable/icon"android:label="@string/app_name">
<activityandroid:name=".ShowWallpaper"
android:theme="@style/Theme"
android:label="@string/app_name">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>



好了,运行程序,可以看到壁纸的显示效果了:(显示的是预设置的动态壁纸:星系)


原创粉丝点击