0
votes

I created an app with navigation drawer. I want to change the color of actionbar and default icon of drawer to be changed on selection of a particular navigation menu item and it should change to default values on selection of any other item.

My code

Fragment fragment;
if(fragment.toString().contains("HomeFragment")){
            ab = ((BaseActivity)getApplicationContext()).getSupportActionBar();
            ab.setHomeButtonEnabled(true);
            ab.setDisplayHomeAsUpEnabled(true);
            ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));
            ab.setElevation(0);
            ab.setDisplayHomeAsUpEnabled(true);
            ab.setHomeAsUpIndicator(R.drawable.username);
    }

I could change actionbar color and navigation drawer icon with the above code,but can't change to default color and icon on other navigation item selection.

1
fragment is never initialized. Anyway inside your fragment findviewbyid and setonclicklistener onclick myviewitem.setbackground...Pomagranite
that is not complete code. fragment is initialized and its working fine. When i select "HomeFragment" color of action bar is changing. But i cant change navigation drawer icon .Visakh

1 Answers

0
votes

Just continue your code

Fragment fragment;
if(fragment.toString().contains("HomeFragment")){
            ab = ((BaseActivity)getApplicationContext()).getSupportActionBar();
            ab.setHomeButtonEnabled(true);
            ab.setDisplayHomeAsUpEnabled(true);
            ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));
            ab.setElevation(0);
            ab.setDisplayHomeAsUpEnabled(true);
            ab.setHomeAsUpIndicator(R.drawable.username);
    } else {
      ab = ((BaseActivity)getApplicationContext()).getSupportActionBar();
            ab.setHomeButtonEnabled(true);
            ab.setDisplayHomeAsUpEnabled(true);
            ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("your default color")));
            ab.setElevation(0);
            //ab.setHomeAsUpIndicator(R.drawable.username); change it to your other icon;
}