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?
mais j'ai une classe avec l'image et le texte en fond d'écran – EliasM
Mais vous voulez définir le fond d'écran pour votre application ou pour le système? – elbaulp
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