Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material Design Navigation drawer icons are grey

How do I make navigation darwer's icon display their true colour?

I designed my own custom icons, but they display with a grey colour in my navdrawer.

The theme I am currently using for the entire app is:Light.DarkActionBar

This is the drawermenu:

    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">


    <item android:title=""
        android:id="@+id/nav_item_inbox"
        />

<item android:title="Home"
          android:id="@+id/nav_item_home"
          android:icon="@drawable/home"

      />

    <item android:title="News">
        <menu>
    <item android:title="Events News"
          android:id="@+id/nav_item_events"
          android:icon="@drawable/ic_action_search"
        />

    <item android:title="International News"
          android:id="@+id/nav_item_international"
          android:icon="@drawable/nav_icong"/>

            <item
                android:title="Climatic News"
                android:id="@+id/nav_item_weathernews"
                android:icon="@drawable/spam"/>
        </menu>
    </item>


    <item android:title="Climate">
        <menu>

            <item
                android:title="Weather Widget"
                android:id="@+id/wewidget"
                android:icon="@drawable/bin"/>
        </menu>
    </item>

    <group android:id="@+id/About">
        <item android:title="About"
            android:id="@+id/abt"
              android:icon="@drawable/settings"/>

        <item android:title="FeedBack"
            android:icon="@drawable/help"/>

        <item android:title="Help"
             android:icon="@drawable/help"/>
    </group>


</menu>

This is the activity_main layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">
    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:fitsSystemWindows="true"
        android:minHeight="?attr/actionBarSize"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:background="?attr/colorPrimary"
        android:animateLayoutChanges="true">
    </android.support.v7.widget.Toolbar>
    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:id="@+id/drawerLayout"
        >
        <FrameLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/containerView">
        </FrameLayout>
        <android.support.design.widget.NavigationView
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:id="@+id/shitstuff"
            app:itemTextColor="@color/black"
            app:menu="@menu/drawermenu"
            android:background="@android:color/white"
            android:layout_marginTop="-24dp"
            />
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

And here is the MainActivity Class:

public class MainActivity extends AppCompatActivity {
    DrawerLayout mDrawerLayout;
    NavigationView mNavigationView;
    FragmentManager mFragmentManager;
    FragmentTransaction mFragmentTransaction;
    View view;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
             mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
             mNavigationView = (NavigationView) findViewById(R.id.shitstuff) ;
             mFragmentManager = getSupportFragmentManager();
             mFragmentTransaction = mFragmentManager.beginTransaction();
             mFragmentTransaction.replace(R.id.containerView,new HomeFragment()).commit();
             mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
             @Override
             public boolean onNavigationItemSelected(MenuItem menuItem) {
                mDrawerLayout.closeDrawers();
                 if (menuItem.getItemId() == R.id.nav_item_home) {
                     FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
                     fragmentTransaction.replace(R.id.containerView,new HomeFragment()).commit();

                 }
                 if (menuItem.getItemId() == R.id.nav_item_events) {
                     FragmentTransaction xfragmentTransaction = mFragmentManager.beginTransaction();
                     xfragmentTransaction.replace(R.id.containerView,new EventsFragment()).commit();
                 }

                 if (menuItem.getItemId() == R.id.nav_item_international) {
                     FragmentTransaction xfragmentTransaction = mFragmentManager.beginTransaction();
                     xfragmentTransaction.replace(R.id.containerView,new InternationalNews()).commit();
                 }
                 if (menuItem.getItemId() == R.id.nav_item_weathernews) {
                     FragmentTransaction xfragmentTransaction = mFragmentManager.beginTransaction();
                     xfragmentTransaction.replace(R.id.containerView, new WeatherNews()).commit();
                 }
                 if (menuItem.getItemId() == R.id.wewidget) {
                     FragmentTransaction xfragmentTransaction = mFragmentManager.beginTransaction();
                     xfragmentTransaction.replace(R.id.containerView,new Weathermain()).commit();
                 }

                 if (menuItem.getItemId() == R.id.abt) {
                     FragmentTransaction xfragmentTransaction = mFragmentManager.beginTransaction();
                     xfragmentTransaction.replace(R.id.containerView,new About()).commit();
                 }
                 return false;
            }

        });
                android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
                //toolbar.setAlpha(0);
                //toolbar.setTranslationY(-300);
                //toolbar.animate().setDuration(1000).translationY(0).alpha(1);

                ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, toolbar, R.string.app_name,
                R.string.app_name);

                mDrawerLayout.setDrawerListener(mDrawerToggle);

                mDrawerToggle.syncState();
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        // Handle action bar actions click
        switch (item.getItemId()) {

            // case R.id.menuitem_recipies:
            //   startActivity(new Intent(this, Recipies.class));
            // Toast.makeText(this, getString(R.string.recs),
            //       Toast.LENGTH_SHORT).show();
            //return true;

            case R.id.menuitem_share:
                startActivity(new Intent(this, Share.class));

                Toast.makeText(this, getString(R.string.ui_menu_share),
                        Toast.LENGTH_SHORT).show();
                return true;
            case R.id.menuitem_feedback:
                startActivity(new Intent(this, Feedback.class));
                Toast.makeText(this, getString(R.string.ui_menu_feedback),
                        Toast.LENGTH_SHORT).show();
                return true;
            case R.id.menuitem_about:
                startActivity(new Intent(this, About.class));
                Toast.makeText(this, getString(R.string.ui_menu_about),
                        Toast.LENGTH_SHORT).show();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

ScreenShot

like image 516
Ray Avatar asked Oct 18 '22 23:10

Ray


1 Answers

Look this Answer,it's perfect to me. navigationView.setItemIconTintList(null); for the reason,In Android code they will make a default ColorStateList:

// NavigationView
final ColorStateList itemIconTint;
if (a.hasValue(R.styleable.NavigationView_itemIconTint)) {
        itemIconTint = a.getColorStateList(R.styleable.NavigationView_itemIconTint);
    } else {
        itemIconTint = createDefaultColorStateList(android.R.attr.textColorSecondary);
}
like image 180
didikee Avatar answered Oct 21 '22 21:10

didikee