编程设置android手机的背景 [英] Programmatically set android phone's background

查看:138
本文介绍了编程设置android手机的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许用户选择从图像的列表的背景下,在用户点击其中的一个和该图像用作背景他的电话。 我的应用程序应该仅仅是另一种版本的Andr​​oid默认的画廊。

I'd like to allow the user to choose a background from a list of images, the user clicks on one of them and that image is used as background for his phone. My app should simply be another version of the android default gallery.

是否有可能以编程方式设置手机的壁纸?

Is it possible to programmatically set the phone's wallpaper?

推荐答案

首先一个,你需要设置权限在Manifest.xml文件

First one, you need set the permission in your Manifest.xml file

 <uses-permission android:name="android.permission.SET_WALLPAPER"/>

,你可以设置此背景:

And you can set the background with this:

Button buttonSetWallpaper = (Button)findViewById(R.id.set);
            ImageView imagePreview = (ImageView)findViewById(R.id.preview);
            imagePreview.setImageResource(R.drawable.five);

            buttonSetWallpaper.setOnClickListener(new Button.OnClickListener(){
            @Override
            public void onClick(View arg0) {
            // TODO Auto-generated method stub
            WallpaperManager myWallpaperManager 
            = WallpaperManager.getInstance(getApplicationContext());
            try {
                myWallpaperManager.setResource(R.drawable.five);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            }});

这工作

这篇关于编程设置android手机的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆