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?

qwertz
  • 6,206
  • 9
  • 40
  • 62
  • 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. – Stephane Sep 26 '15 at 12:48
  • 1
    @StephaneEybert I just downloaded the Cheesesquare example by Chris Banes from Github and copied it from there – qwertz Sep 26 '15 at 12:51

4 Answers4

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);
        }
    }
}
Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
10

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>
Community
  • 1
  • 1
Soheil
  • 325
  • 4
  • 19
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.

Shubham Sharma
  • 166
  • 1
  • 7
0

you can use it in apptheme in style :

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

mahsa k
  • 555
  • 6
  • 9