Bonjour à tous,

Est-il possible de modifier le background d'un button appartenant à un fragment.

Dans mon fichier XML main.xml j'ai :
- une image qui s'affiche sur la totalité de mon écran (fond d'écran)
- puis une partie supérieure de l'IHM plusieurs ImageView et Button.
- et enfin une partie inférieure de l'IHM le fameux android.support.v4.view.ViewPager

main.xml:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff0000">
    <ImageView
		android:id="@+id/IdImgFondEcran"
		android:src="@drawable/fond_ecran"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_gravity="center"
		/>
		<Button
		android:id="@+id/IdButonErase"
		android:background="@drawable/button_erase"
		android:onClick="fonctionErase"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginTop="25px"
		android:layout_marginLeft="4px"
		/>
	<ImageView
		android:id="@+id/IdIconBatteryLevel"
		android:src="@drawable/icon_battery"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginTop="34px"
		android:layout_marginLeft="1179px"
		/>
         <FrameLayout android:id="@+id/IdLayoutMain" 
    	        android:layout_width="wrap_content"
    	        android:layout_height="wrap_content"
    	        android:layout_marginTop="250px">
  			<android.support.v4.view.ViewPager
  			android:id="@+android:id/viewpager"
  			android:layout_width="wrap_content"
 			android:layout_height="wrap_content"
  			/>
  	</FrameLayout>
</FrameLayout>
J'ai également deux fragments avec des Button
layout_fragment1.xml (avec sa classe associée RemoteFragment1.java) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
  <Button
		android:id="@+id/IdButtonPlus"
		android:background="@drawable/button_plus"
		android:onClick="incremente"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginTop="48px"
		android:layout_marginLeft="184px"
		/>
 
	<Button
		android:id="@+id/IdButtonMoins"
		android:background="@drawable/button_moins"
		android:onClick="defineChannel"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginTop="158px"
		android:layout_marginLeft="184px"
		/>
<FrameLayout/>
layout_fragment2.xml (avec sa classe associée RemoteFragment2.java) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
  <Button
		android:id="@+id/IdButtonBleu"
		android:background="@drawable/button_plus"
		android:onClick="clicBleu"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginTop="48px"
		android:layout_marginLeft="184px"
		/>
 
	<Button
		android:id="@+id/IdButtonRouge"
		android:background="@drawable/button_moins"
		android:onClick="clicRouge"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginTop="158px"
		android:layout_marginLeft="184px"
		/>
<FrameLayout/>
J'ai également une classe PagerAdapter dérivant de FragmentPagerAdapter et enfin la classe ViewPagerFragmentActivity dérivant de FragmentActivity

ViewPagerFragmentActivity .java :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
public class ViewPagerFragmentActivity extends FragmentActivity{
 
        private static ViewPager pager;
 
	private PagerAdapter mPagerAdapter;
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.main);
 
        //initialise the pager
        this.initialisePaging();
        }
 
         /**
         * Initialise the fragments to be paged
         */
	private void initialisePaging() {
 
		List<Fragment> fragments = new Vector<Fragment>();
fragments.add(Fragment.instantiate(this,RemoteFragment1.class.getName()));
		fragments.add(Fragment.instantiate(this, RemoteFragment2.class.getName()));
		this.mPagerAdapter  = new PagerAdapter(super.getSupportFragmentManager(), fragments);
		//
		pager = (ViewPager)super.findViewById(R.id.viewpager);
		pager.setAdapter(this.mPagerAdapter);
	}
}
Je voudrais savoir si il est possible de changer le background du Button "IdButtonPlus" du layout_fragment1.xml. Par exemple, lors de l'affichage du fragment1, suivant la valeur d'un boolean :
true -> android:background="@drawable/button_plus"
false -> android:background="@drawable/button_gris"

Est-ce possible ? Avez vous des suggestions à me faire ?