NavigationView menu items with counter on the right

Starting from version 23 of appcompat-v7 NavigationView supports action views, so it is quite easy to implement counter yourself. Create counter layout, i.e. 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=”match_parent” android:gravity=”center_vertical” android:textAppearance=”@style/TextAppearance.AppCompat.Body2″ /> Reference it in your drawer menu xml, i.e. menu/drawer.xml: <item … app:actionLayout=”@layout/menu_counter” /> Note that you should use app namespace, don’t … Read more

Custom back button for NavigationView’s navigation bar in SwiftUI

TL;DR Use this to transition to your view: NavigationLink(destination: SampleDetails()) {} Add this to the view itself: @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode> Then, in a button action or something, dismiss the view: presentationMode.wrappedValue.dismiss() Full code From a parent, navigate using NavigationLink NavigationLink(destination: SampleDetails()) {} In DetailsView hide navigationBarBackButton and set custom back button to leading navigationBarItem, … Read more

How to set custom typeface to items in NavigationView?

just add following class file to your project. import android.graphics.Paint; import android.graphics.Typeface; import android.text.TextPaint; import android.text.style.TypefaceSpan; public class CustomTypefaceSpan extends TypefaceSpan { private final Typeface newType; public CustomTypefaceSpan(String family, Typeface type) { super(family); newType = type; } @Override public void updateDrawState(TextPaint ds) { applyCustomTypeFace(ds, newType); } @Override public void updateMeasureState(TextPaint paint) { applyCustomTypeFace(paint, newType); } … Read more

How to customize item background and item text color inside NavigationView?

itemBackground, itemIconTint and itemTextColor are simple xml-attributes that can be set, though you have to use a custom prefix instead of the android: one. Example <android.support.v4.widget.DrawerLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/drawer_layout” android:layout_width=”match_parent” android:layout_height=”match_parent” android:fitsSystemWindows=”true”> <!– Other layout views –> <android.support.design.widget.NavigationView android:id=”@+id/nav_view” android:layout_width=”wrap_content” android:layout_height=”match_parent” android:layout_gravity=”start” android:fitsSystemWindows=”true” app:itemBackground=”@drawable/my_ripple” app:itemIconTint=”#2196f3″ app:itemTextColor=”#009688″ app:headerLayout=”@layout/nav_header” app:menu=”@menu/drawer_view” /> </android.support.v4.widget.DrawerLayout> Note: In this case the … Read more

NavigationView and custom Layout

Here’s how I solved it, and worked perfectly: <android.support.design.widget.NavigationView android:id=”@+id/navigation” android:layout_width=”wrap_content” android:layout_height=”match_parent” android:layout_gravity=”start” android:fitsSystemWindows=”true”> <LinearLayout android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical”> <include layout=”@layout/nav_header” /> <ListView android:id=”@+id/lst_menu_items” android:layout_width=”match_parent” android:layout_height=”0dp” android:layout_weight=”1″ /> </LinearLayout> </android.support.design.widget.NavigationView>

How to create a simple divider in the new NavigationView?

All you need to do is define a group with an unique ID, I have checked the implementation if group has different id’s it will create a divider. Example menu, creating the separator: <menu xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” tools:context=”.MainActivity”> <group android:id=”@+id/grp1″ android:checkableBehavior=”single” > <item android:id=”@+id/navigation_item_1″ android:checked=”true” android:icon=”@drawable/ic_home” android:title=”@string/navigation_item_1″ /> </group> <group android:id=”@+id/grp2″ android:checkableBehavior=”single” > <item android:id=”@+id/navigation_item_2″ … Read more

NavigationView get/find header layout

Version 23.1.0 switches NavigationView to using a RecyclerView (rather than the previous ListView) and the header is added as one of those elements. This means it is not instantly available to call findViewById() – a layout pass is needed before it is attached to the NavigationView. For version 23.1.1 of the Support Library, you can … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)