Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <menu xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto">
- <group android:checkableBehavior="single">
- <item
- android:id="@+id/nav_camera"
- android:icon="@drawable/ic_menu_camera"
- android:title="Import" />
- <item
- android:id="@+id/nav_gallery"
- app:actionViewClass="android.widget.TextView"
- android:icon="@drawable/ic_menu_gallery"
- android:title="Gallery" />
- <item
- android:id="@+id/nav_slideshow"
- app:actionViewClass="android.widget.TextView"
- android:icon="@drawable/ic_menu_slideshow"
- android:title="Slideshow" />
- <item
- android:id="@+id/nav_manage"
- android:icon="@drawable/ic_menu_manage"
- android:title="Tools" />
- </group>
- //Create these objects above OnCreate()of your main activity
- TextView slideshow,gallery;
- //These lines should be added in the OnCreate() of your main activity
- gallery=(TextView) MenuItemCompat.getActionView(navigationView.getMenu().findItem(R.id.nav_gallery));
- slideshow=(TextView) MenuItemCompat.getActionView(navigationView.getMenu().findItem(R.id.nav_slideshow));
- //This method will initialize the count value
- initializeCountDrawer();
- private void initializeCountDrawer() {
- //Gravity property aligns the text
- gallery.setGravity(Gravity.CENTER_VERTICAL);
- gallery.setTypeface(null, Typeface.BOLD);
- gallery.setTextColor(getResources().getColor(R.color.colorAccent));
- gallery.setText("99+");
- slideshow.setGravity(Gravity.CENTER_VERTICAL);
- slideshow.setTypeface(null,Typeface.BOLD);
- slideshow.setTextColor(getResources().getColor(R.color.colorAccent));
- //count is added
- slideshow.setText("7");
- }
- NavigationView navigation = (NavigationView)findViewById(R.id.navigation);
- Menu menuNav = navigation.getMenu();
- MenuItem element = menuNav.findItem(R.id.item5);
- String before = element.getTitle().toString();
- String counter = Integer.toString(5);
- String s = before + " "+counter+" ";
- SpannableString sColored = new SpannableString( s );
- sColored.setSpan(new BackgroundColorSpan( Color.GRAY ), s.length()-3, s.length(), 0);
- sColored.setSpan(new ForegroundColorSpan( Color.WHITE ), s.length()-3, s.length(), 0);
- element.setTitle(sColored);
Add Comment
Please, Sign In to add comment