Remove scrollbar from android support design navigation drawer?
Asked Answered
J

4

16

I just updated the support design library from 22.2.1 to 23.0.1 and immediately noticed the presence of a scrollbar in the navigation drawer. I tried to use

android:scrollbars="none"

But that didn't fix it. Is there any other way to remove the scrollbar?

Jerejereld answered 19/9, 2015 at 21:12 Comment(2)
May I ask if you found a recent article on how to implement the navigation drawer ? Lots of articles are at least a year old.Stanleigh
@StephaneEybert I just downloaded the Cheesesquare example by Chris Banes from Github and copied it from thereJerejereld
C
39

Unfortunately the scrollbar is set in the NavigationMenuView layout not in the NavigationView, for this reason if you use android:scrollbars="none" the scrollbar is still present.

You can do it programmatically calling this method:

private void disableNavigationViewScrollbars(NavigationView navigationView) {
    if (navigationView != null) {
        NavigationMenuView navigationMenuView = (NavigationMenuView) navigationView.getChildAt(0);
        if (navigationMenuView != null) {
            navigationMenuView.setVerticalScrollBarEnabled(false);
        }
    }
}
Caroylncarp answered 20/9, 2015 at 17:35 Comment(0)
B
11

You can also use following style in your style.xml

<item name="android:scrollbarThumbVertical">@color/transparent</item>
if you don't have a transparent color defined in colors.xml, use the android library "transparent" with: <item name="android:scrollbarThumbVertical">@android:color/transparent</item>
Brakesman answered 10/7, 2016 at 2:12 Comment(0)
S
0

I tried doing this in Kotlin, hope it will be a help. first, create different fragments and any navigation you want to after that create a function which will be used to load fragments into the activity.

    when (item.getItemId()) {
            R.id.home -> {
                //this is the name of the method I am using for adding fragments 
                //with bottom navigation bar you can use it with any type o navigation.
                loadFragment(getString(R.string.home_fragment), HomeFragment());
                appBar.title = "Home"
                return true
            }
            R.id.jobs -> {
                loadFragment(getString(R.string.jobs_fragment), JobsFragment());
                appBar.title = "Jobs"
                return true
            }

after that here is the method

        private fun loadFragment(tag: String,loadFragment: Fragment) {
           val fManager = supportFragmentManager
            val fTransaction = fManager.beginTransaction()
            val fragment = fManager.findFragmentByTag(tag)

            if (fragment == null) {
                fTransaction.replace(R.id.activity_main_content_main, loadFragment,tag);
            } else { // re-use the old fragment
                fTransaction.replace(R.id.activity_main_content_main, fragment, tag);
            }

            fTransaction.addToBackStack(tag);
            fTransaction.commit();

        }

first val fragment = fManager.findFragmentByTag(tag) this will search if the fragment is already loaded then else statement will be executed and the preloaded fragment will be displayed but if not then loadFragment parameter we passed contains the fragment you want to load then if statement will be executed which will load the passed fragment.

Sarraute answered 8/2, 2019 at 12:35 Comment(0)
E
0

you can use it in apptheme in style :

<item name="android:scrollbarThumbVertical">@android:color/transparent</item>

Elate answered 13/5, 2019 at 19:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.