I have my pull-down menu with its respective items. But I would like to add to each item the TextView that is seen in the image that says PREMIERE. How can I add it?
This is the image of how I am now:
In your layout of the "item" add another TextView
where you can add the text "Premieres", this is an example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@android:color/holo_green_dark">
<ImageView
android:id="@+id/icon"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:contentDescription="@null"
android:src="@drawable/ic_subway"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/icon"
android:text = "Seccion"
android:textColor="@android:color/white"
android:gravity="center_vertical"
android:paddingRight="40dp"/>
<TextView android:id="@+id/category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text = "Estrenos"
android:layout_marginRight="8dp"
android:textColor="@android:color/white"/>
</RelativeLayout>
@NicolasSchmidt, I recommend you see the example of this link:
link that I posted in another answer, you can configure your view, in this case add the TextView
so that the text "Premieres" appears, see drawer_list_item.xml
.
What I can think of is that you create a new layout
with the textview i.e texto_estreno.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="Estrenos"/>
Afterwards in your DrawerMenu
item
you can refer to the layout where the Textview
is, i.e:
<item app:actionLayout="@layout/texto_estreno" />
That way you can customize the layout where the text is "Releases "to your liking, colors, styles, font type, etc.
UPDATE
Another way that is not the best is to do it with SpannableString
:
I'm not sure about the number of the characters, it's a matter of placing the corresponding number:
NavigationView navigation = (NavigationView)findViewById(R.id.navigation);
Menu menuNav = navigation.getMenu();
MenuItem element = menuNav.findItem(R.id.item5); //Aquí colocas tu item
String before = element.getTitle().toString();
String texto = "Estrenos";
String s = before + " "+texto+" ";
SpannableString sColored = new SpannableString( s );
sColored.setSpan(new BackgroundColorSpan( Color.GRAY ),3, 3, 0);
sColored.setSpan(new ForegroundColorSpan( Color.WHITE ), 3, 3,0);
element.setTitle(sColored);