Search code examples
androidxmlnavigation-drawer

Style not getting applied to NavigationView menu in NavigationDrawer


Style is not being applied to the menu, not sure what is wrong here, seems ok to me. I want the drawer menu items to be bold. Am I missing something here

activity_main.

<com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view_container"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_marginTop="@dimen/height_toolbar"
        android:fitsSystemWindows="false"
        style="@style/NavigationDrawerStyle"
        app:elevation="4dp">

        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <com.google.android.material.navigation.NavigationView
                    android:id="@+id/nav_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="top"
                    android:scrollbars="none"
                    style="@style/NavigationDrawerStyle"
                    app:elevation="0dp"
                    app:itemBackground="@drawable/nav_drawer_divider"
                    app:menu="@menu/activity_main_drawer" />

                <com.google.android.material.navigation.NavigationView
                    android:id="@+id/nav_view_footer"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:background="@color/bg_color"
                    android:scrollbars="none"
                    style="@style/NavigationDrawerStyle"
                    app:elevation="0dp"
                    app:menu="@menu/activity_main_drawer_footer" />
            </LinearLayout>
        </androidx.core.widget.NestedScrollView>

styles.xml

 <!-- navigation drawer style -->
    <style name="NavigationDrawerStyle" parent="AppTheme">

        <item name="android:textAllCaps">true</item>
    </style>

Also, an additional question is how can I make part of the text bold. for example, if I have menu item "Mein Garten" I want only "Mein" to be bold please check the image attached

enter image description here


Solution

  • so i figured out the issue, i was applying style the wrong way in NavigationView. Here is what i changed

    before

    style="@style/NavigationDrawerStyle"
    

    after

    app:itemTextAppearance="@style/NavigationDrawerStyle"