Well, I'm trying to change my drawer navigator whenever I change the fragment, I managed to change the ActionBar color and the Background color, but the thing is that with the Background is not enough... I saw that I declare a BackgroundResource with other colors, and when I try to change the color it does not work.
My MainActivity.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Displaying Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!-- Displaying Drawer -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/drawer_list_selection"
android:background="@color/list_background"/>
</android.support.v4.widget.DrawerLayout>
My colors.xml (I've tried to change it manually but I don't know how to do, then I've created as colors as items are on my drawable navigator).
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="list_item_title">#fff</color>
<color name="list_background">#458A79</color>
<color name="list_background2">#ffc591</color>
<color name="list_background3">#ab91ff</color>
<color name="list_background4">#f784fe</color>
<color name="list_background5">#91dfff</color>
<color name="list_background_pressed">#6FA698</color>
<color name="list_background_pressed2">#ffc591</color>
<color name="list_background_pressed3">#ab91ff</color>
<color name="list_background_pressed4">#f784fe</color>
<color name="list_background_pressed5">#91dfff</color>
<color name="list_divider">#fff</color>
<color name="counter_text_bg">#626262</color>
<color name="counter_text_color">#c5c4c4</color>
</resources>
And the thing that I've tried on my MainActivity.java is
private void displayView(int position) {
// update the main content with called Fragment
Fragment fragment = null;
LlistaGenericaFragment frag = null;
FragmentTransaction ft = null;
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#256F5C")));
switch (position) {
case 0:
fragment = new MetallsAlcalinsFragment();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffc591")));
mDrawerList.setBackground(new ColorDrawable(Color.parseColor("#ffc591"))); //set the background but not the ListView
mDrawerList.setBackgroundResource(R.color.list_background2); //Don't see any change
break;
I know I'm doing something wrong, but I don't get what... Could you explain me how can I change this each time I change the fragment?