Android Material Design navigation drawer menu icon chage

3.6k views Asked by At

I implemented a Material Design nav drawer using this example. I customize it according to my theme. Everything is working perfectly. Just the last thing I want to customize it's menu icon. I googled it, but have not find any good solution. I want to change its color if possible , or add a custom drawable. Any solution on idea. Thanks in advance enter image description here

This is my Application theme which i set in menifest

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColorPrimary">@color/textColorPrimary</item>
        <item name="android:windowBackground">@color/windowBackground</item>

    </style>

And this is my toolbar style

<

style name="GalaxyZooThemeToolbarDarkOverflow" parent="Theme.AppCompat.NoActionBar">
           <item name="android:textColorPrimary">@color/headerColor</item>
    <item name="android:iconPreview">@drawable/ic_launcher</item>

<item name="actionMenuTextColor">@color/colorPrimaryDark</item>
<item name="android:textColorSecondary">@color/headerColor</item>

My Main activity code

public class Activity_Home extends ActionBarActivity implements FragmentDrawer.FragmentDrawerListener {

    private static String TAG = Activity_Home.class.getSimpleName();

    private Toolbar mToolbar;
    private FragmentDrawer drawerFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_drawer);

        mToolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayShowHomeEnabled(true);


        drawerFragment = (FragmentDrawer)
                getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
        drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
        drawerFragment.setDrawerListener(this);

        // display the first navigation drawer view on app launch
        displayView(0);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity__main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }
//
//      if(id == R.id.action_search){
//          Toast.makeText(getApplicationContext(), "Search action is selected!", Toast.LENGTH_SHORT).show();
//          return true;
//      }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onDrawerItemSelected(View view, int position) {
        displayView(position);
    }

    private void displayView(int position) {

    }
}
2

There are 2 answers

0
Nouman Ghaffar On BEST ANSWER

Found a sloution myself. It was pretty easy indeed. All you have to do is set a toolbar style. In your style primary color act as a toolbar title and textScondary color act as a menu icon color.

    style name="GalaxyZooThemeToolbarDarkOverflow" parent="Theme.AppCompat.NoActionBar">
           <item name="android:textColorPrimary">@color/headerColor</item>
    <item name="android:iconPreview">@drawable/ic_launcher</item>

<item name="actionMenuTextColor">@color/colorPrimaryDark</item>
<item name="android:textColorSecondary">@color/headerColor</item>
2
Bartek Lipinski On

Add:

getSupportActionBar().setHomeAsUpIndicator(resId);

or

getSupportActionBar().setHomeAsUpIndicator(drawable);

to your Activity's onCreate