1

Hello I'm using badge counter in navigation menu, but. I can't move to center vertically. I tried margin, height:match_parent but width shape not success.

( https://stackoverflow.com/a/33607630/4933464 ) Here my codes ( I use with shape ):

@drawable/menu_counter.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#ec443e" />
    <padding
        android:left="5dp"
        android:right="5dp"
        android:top="3dp"
        android:bottom="3dp"/>
    <corners android:radius="5dp" />
</shape>

@layout/menu_counter.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@drawable/menu_counter"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="#ffffff" />

Thanks.

Community
  • 1
  • 1
Mehmet Hanoğlu
  • 2,942
  • 1
  • 13
  • 19

2 Answers2

0

Original DrawerLayout doesn't support badges. But there is a many useful library

MaterialDrawer : https://github.com/mikepenz/MaterialDrawer

Screenshots aviable on github page.

Mehmet Hanoğlu
  • 2,942
  • 1
  • 13
  • 19
0

Wrap it with a relative layout and add

android:layout_centerVertical="true"

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="match_parent">

      <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:gravity="center"
       android:layout_centerVertical="true"
       android:background="@drawable/menu_counter"
       android:textAppearance="@style/TextAppearance.AppCompat.Body2"
       android:textColor="#ffffff" />
</RelativeLayout>
Ankur
  • 677
  • 1
  • 7
  • 21