2014-05-24 1 views
0

j'ai fait mon propre fond d'écran et je ne sais pas comment définir quand l'utilisateur a cliqué sur le bouton « Déf »Set mywallpaper dans android après bouton emboutie

je l'ai écrit:

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

Mais pas le code, j'ai besoin de ton aide.

Répondre

1

c'est ma solution .... lancer avec intention le MyWallPaperService

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

merci!

0

Vous pouvez changer l'arrière-plan d'un Activity:

  • Dans la mise en page Activity, le réglage de la racine View (Normalement, un LinearLayour ou RelativeLayout) avec android:background="@drawable/yourdrawable"

  • Programatically:

    LinearLayout ll = (LinearLayout) findViewById(R.id.myLinearLayout); 
    ll.setBackgroundDrawable(...) 
    
  • Ou avec un thème pour votre application ou Activity.

Dans votre cas, cela vous intéresse de le modifier par programme, vous devrez donc utiliser la deuxième option. Vous devez ajouter un onClickListener à votre bouton et changer dans l'arrière-plan, quelque chose comme ceci:

myButton.setOnClickListener(new OnClickListener() { 

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

Soit dit en passant, de changer l'arrière-plan de votre activité que vous n'avez pas besoin utiliser permisions

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

vous avez des questions similaires:

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?

+0

mais j'ai une classe avec l'image et le texte en fond d'écran – EliasM

+0

Mais vous voulez définir le fond d'écran pour votre application ou pour le système? – elbaulp

+0

Dans mon application (wallpapercustom) je veux mettre un bouton dans une activité et qui dit "SET WALLPAPER" et serait changement de fond d'écran de mon téléphone – EliasM