wbk727
wbk727

Reputation: 8408

How to change colour of navigation drawer section titles

I'm trying to change the colour of section titles but I can find any options within the xml nor java as I type. The title is called 'Section' but appears in black hence I cannot see it. How can it be changed to white?

activity_main.xml

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true">


    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_height="match_parent"
        android:layout_width="320dp"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"

        android:background="#000000"
        app:itemTextColor="#FFFFFF"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_view"/>

</android.support.v4.widget.DrawerLayout>

MainActivity.java

public class MainActivity extends ActionBarActivity {

    private DrawerLayout mDrawerLayout;

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

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        if (navigationView != null) {
            setupDrawerContent(navigationView);
        }
    }

    private void setupDrawerContent(NavigationView navigationView) {
        navigationView.getMenu()
                .findItem(R.id.navigation_item_1)
                .getIcon()
                .setColorFilter(Color.parseColor("#B36305"), PorterDuff.Mode.SRC_ATOP);
    }
}

drawer_view.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:title="Section">
        <menu>
            <item
                android:id="@+id/navigation_item_1"
                android:icon="@drawable/ic_browncircle"
                android:title="Sub item 1" />
        </menu>
    </item>
</menu>

enter image description here

enter image description here

Upvotes: 0

Views: 705

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199825

Subheaders use the android:textColorSecondary from your theme for the text color - make sure this is set to a light color (as would be the default for Theme.AppCompat.NoActionBar).

Upvotes: 3

Related Questions