Tengo mi menu desplegable con sus respectivos items. Pero me gustaria agregarle a cada item el TextView que se ve en la imagen que dice ESTRENOS. Como lo puedo agregar?
Esta es la imagen de como me queda ahora:
Stack Overflow en español es un sitio de preguntas y respuestas para programadores y profesionales de la informática. Solo te toma un minuto registrarte.
Regístrate para unirte a esta comunidadTengo mi menu desplegable con sus respectivos items. Pero me gustaria agregarle a cada item el TextView que se ve en la imagen que dice ESTRENOS. Como lo puedo agregar?
Esta es la imagen de como me queda ahora:
En tu layout del "item" agrega otro TextView
donde tu puedas agregar el texto "Estrenos", este es un ejemplo:
<?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, te recomiendo veas el ejemplo de este link :
http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/ que publiqué en otra respuesta, tu vista la puedes configurar, en este caso agregar el TextView
para que aparezca el texto "Estrenos", ver drawer_list_item.xml
.
Lo que se me ocurre es que crees un nuevo layout
con el 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"/>
Ya después en tu DrawerMenu
item
puedes hacer referencia al layout donde está el Textview
, i.e:
<item app:actionLayout="@layout/texto_estreno" />
De esa manera lo puedes costumizar el layout donde está el texto "Estrenos " a tu gusto, colores, estilos, tipo de fuente, etc.
ACTUALIZACIÓN
Otra forma que no es la mejor es hacerlo con SpannableString
:
No estoy seguro con el número de los caracteres, ya es cuestión que le coloques el número que corresponde:
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);
<item app:actionLayout="@layout/texto_estreno" />
me refiero a que por ejemplo tienes el item con el texto "hola" ahí mismo dentro de ese mismo item colócale app:actionLayout="@layout/texto_estreno"
y no crees otro item, no se si me entiendes.