EliasM
EliasM

Reputation: 769

Set mywallpaper in android after pressed button

I made my own wallpaper and I don't know how to set this when the user clicked over button “SET WALLPAPER”

I wrote:

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

But not the code, I need your help.

Upvotes: 0

Views: 922

Answers (2)

EliasM
EliasM

Reputation: 769

this is my solution .... launch with Intent the MyWallPaperService

Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
                            intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
                                new ComponentName(getApplicationContext(), MyWallpaperService.class));
                            startActivity(intent);

thanks!

Upvotes: 2

Alejandro Alcalde
Alejandro Alcalde

Reputation: 6220

You can change the background of one Activity:

  • In the Activity layout, setting the root View (Normally a LinearLayour or RelativeLayout) with android:background="@drawable/yourdrawable"

  • Programatically:

    LinearLayout ll = (LinearLayout) findViewById(R.id.myLinearLayout);
    ll.setBackgroundDrawable(...)
    
  • Or with a theme for your app or Activity.

In your case, you are interested in changed it programatically, so you would need to use the second option. You need to add a onClickListener to your button and inside change the background, something like this:

    myButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            LinearLayout ll = (LinearLayout) findViewById(R.id.myLinearLayout);
            ll.setBackgroundDrawable(...)
        }
    });

By the way, to change the background of your activity you do not need use permisions

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

Here you have similar questions:

How to programmatically change the background image of an Android Activity

Change Layout-background on click programmatically

Android: Changing Background-Color of the Activity (Main View)

How to set background color of an Activity to white programmatically?

Upvotes: 0

Related Questions