android-navigationview

Fixed navigation header in navigation drawer while scrolling through items

戏子无情 提交于 2019-12-01 08:44:07
问题 CURRENT STATE : NavigationDrawer with a NavigationHeader and NavigationMenu items. The items are large in number so scrolling is required in order to access the items towards the bottom. REQUIREMENT : When scrolling down to the bottom, the NavigationHeader should stay fixed Here's my activity_main layout file <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android

How to add click event to item on NavigationView of Android

℡╲_俬逩灬. 提交于 2019-12-01 04:18:45
问题 I am trying to implement Sidebar NavigationDrawer in my Android project. To do so, I have used NavigationView in DrawerLayout . To show items I used menu. I want to add click event on that added menu items. Code for reference: In navigation menu - <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/nav_account" android:title="My Account"/> <item android:id="@+id/nav_settings" android:title="Settings"/> <item android

Overlapping shadow effect remains on Navigation Drawer's NavigationView

我的梦境 提交于 2019-11-30 01:51:14
问题 I have refined the Navigation Drawer Activity project template of Android Studio, which uses Toolbar , v7.app.ActionBarDrawerToggle and NavigationView instead of the NavigationDrawerFragment (and layout/fragment_navigation_drawer.xml). It is perfectly working. Then, I go further. I have my Navigation Drawer project in immersive-sticky (full screen) mode. @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) { View decorationView =

How to uncheck checked items in Navigation View?

帅比萌擦擦* 提交于 2019-11-29 10:42:20
问题 I know it's possible to highlight a navigation view item by calling setCheckedItem() or return true value in onNavigationItemSelected to display the item as the selected item, but How can I uncheck the checked items of a navigation view? 回答1: This will uncheck the items: int size = mNavigationView.getMenu().size(); for (int i = 0; i < size; i++) { mNavigationView.getMenu().getItem(i).setCheckable(false); } 回答2: I saw @arsent solution and gave it a try, and it will indeed do what you want,

NavigationView(Change Color of Selected Item)

一曲冷凌霜 提交于 2019-11-29 01:40:01
Is there any way to change the Item color programmatically of the selected item in the navigation drawer? I'am able to use the app:itemTextColor, but the problem is if i used this, the checked in the menu item will not highlight. <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <group android:checkableBehavior="single"> <item android:id="@+id/nav_home" android:icon="@drawable/ic_home_black_24dp" android:title="Home" /> <item android:id="@+id/nav_search" android:icon="@drawable/ic_search_black" android:title="Search Location" /> <item

How to set a long click listener on a MenuItem (on a NavigationView)?

一个人想着一个人 提交于 2019-11-28 12:02:21
How can I set a long click listener on a MenuItem ? I tried this answer , but the method doesn't exist for me. Any solutions? Code: Menu menu = navigationView.getMenu(); MenuItem menuItem = menu.findItem(R.id.menu_item); // TODO set a long click listener on the menuItem. menuItem.setOnLongClickListener(...); // Method does not exist, any other solutions? Edit: I don't want to set a custom ActionView, I want the long click listener to the whole MenuItem , without a custom View. one of many ways (assuming we use Toolbar) - this example should give you the idea how to implement long click on

Android NavigationView: reduce space between icon and text and `itemBackground` not working

廉价感情. 提交于 2019-11-28 09:14:55
Is there a way to reduce the space between the icon and text in the NavigationView when its built using a menu xml? I've tried to text android:drawablePadding using the app:itemTextAppearance attribute and that doesn't work, I've tried setting the padding and margins and nothing works. Also, when I set app:itemBackground and set the checked state, the entire menu item doesn't highlight, I get something like the picture below. The xml used to create the itemBackground is: <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="

In android how to set navigation drawer header image and name programmatically in class file?

血红的双手。 提交于 2019-11-27 17:09:38
In android studio 1.4.1, I have created new Navigation Drawer Project which is default.My issue is in this project there is nav_header_main.xml file which is for navigation header image and name. I want this image and name should be set programmatically in my main class activity. How to do this, I tried lot but the app crashes. nav_header_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="match_parent" android:id="@+id/headerView" android:layout_height="@dimen/nav_header_height" android:background="@drawable/side_nav_bar" android:gravity="bottom" android

NavigationView: how to insert divider without subgroup?

你。 提交于 2019-11-27 14:37:00
How I can put a divider without title Subgroup in the new NavigationView? <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <group android:checkableBehavior="single"> <item android:id="@+id/drawer_armario" android:icon="@drawable/armario" android:title="@string/armario" /> <item android:id="@+id/drawer_amigos" android:icon="@drawable/amigos" android:title="@string/amigos" /> </group> <item android:title="Configuración"> <menu> <item android:id="@+id/drawer_ajustes" android:icon="@drawable/ajustes" android:title="@string/ajustes" /> <item

Default Navigation Drawer View to ExpandableListView

孤者浪人 提交于 2019-11-27 13:45:26
In Android Studio 2.1.2, if i create a default navigation activity I get this view: Which uses the following activity_main.xml file: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout 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" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:openDrawer="start"> <include layout="@layout/app_bar_main" android:layout_width="match