android 壁纸服务,Android开发学习之WallPaper设置壁纸详细介绍与实例

本文详细介绍了在Android中设置壁纸的三种方法:通过WallpaperManager的setResource和setBitmap方法,以及重写ContextWrapper的setWallpaper()。文章通过一个实例展示了如何实现一个简单的壁纸应用,使用Gallery选择图片,点击按钮将其设置为壁纸,同时包含了必要的权限设置和代码实现。
摘要由CSDN通过智能技术生成

今天和大家分享的是关于在android中设置壁纸的方法,在android中设置壁纸的方法有三种,分别是:

1、使用wallpapermanager的setresource(int resourceid)方法

2、使用wallpapermanager的setbitmap(bitmap bitmap)方法

3、重写contextwrapper 类中提供的setwallpaper()

除此之外,我们还需要在应用程序中加入下列权限:

下面我们以此为基本方法,来实现android中自带的壁纸应用。首先来看我的布局代码:

复制代码 代码如下:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical"

android:background="#000000"

tools:context=".mainactivity" >

android:id="@+id/imageswitcher"

android:layout_width="fill_parent"

android:layout_height="370dp">

android:id="@+id/gallery"

android:layout_width="fill_parent"

android:layout_height="80dp"

android:layout_below="@+id/imageswitcher"  />

android:id="@+id/btngo"

android:layout_width="wrap_content"

android:layout_height="40dp"

android:layout_below="@+id/gallery"

android:layout_alignparentbottom="true"

android:layout_centerhorizontal="true"

android:text="@string/btngo&

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值