How to change the font and color of the navigation Drawer side menu

Asked

Viewed 626 times

1

Hello, I have a project created as DrawerLayout and would like to customize by changing the type of font, size and color. but I can’t.

inserir a descrição da imagem aqui

Change part to red.

1 answer

0


First, go to res/values/Styles and create the following themes

For your Navigation items:

 <style name="NavigationItemAppearance">
    <item name="android:textColor">#8BC34A</item>
    <item name="android:textSize">30sp</item>
    <item name="android:fontFamily">sans-serif-condensed-light</item>
</style>

And another case also wants to change the appearance of the Subtitulos:

<style name="NavigationSubTitleAppearance">
    <item name="android:textColor">#8BC34A</item>
    <item name="android:textSize">20sp</item>
    <item name="android:fontFamily">sans-serif-condensed-light</item>
</style>

remember to set the font size, color and font of your taste.

Go to the xml of Activity that is the Navigation Drawer and add inside the Navigation:

 app:itemTextAppearance="@style/NavigationItemAppearance"

Done. Now continuing in case you want to change the Subtitulles, where your Welcome and Prepaid is, do as follows:

Open the xml where your navigation menu is and add an id to the Subttulles:

<item android:title="Bem-vindo"
    android:id="@+id/welcome">

For all subtletes you want to change

 <item android:title="Pré-Pago"
            android:id="@+id/pre_pago">

In your Activity class where Navigation is, before the

navigationView.setNavigationItemSelectedListener(this);

Appendage:

    Menu myMenu = navigationView.getMenu();
    MenuItem welcome= myMenu.findItem(R.id.welcome);
    SpannableString sWelcome = new SpannableString(welcome.getTitle());
    sWelcome.setSpan(new TextAppearanceSpan(this, R.style.NavigationSubTitleAppearance), 0, sWelcome.length(), 0);
    welcome.setTitle(sWelcome);

Do the same for all subtletes you want to change

    MenuItem prePago= myMenu.findItem(R.id.pre_pago);
    SpannableString sPrePago = new SpannableString(prePago.getTitle());
    sPrePago.setSpan(new TextAppearanceSpan(this, R.style.NavigationSubTitleAppearance), 0, sPrePago.length(), 0);
    prePago.setTitle(sPrePago);

the result would be something like this:

inserir a descrição da imagem aqui

I hope I helped, hug

  • Bro, ball show. And to change the background color, take off this white color?

  • @Arimelo in xml inside your Navigationview just add 'android:background="#FF0000" ' change the color you want. Hug

  • Blz, vlw I got it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.