LoginSignup
3
2

More than 5 years have passed since last update.

Navigation Drawerのスクロールバーを消す方法

Last updated at Posted at 2017-06-13

XML上でスクロールバーを消すことはできない

XML上のNavigationViewに対して、以下のようにスクロールバーを消そうとしたが消えない。

android:scrollbars="none"

NavigationViewの構成

NavigationViewの実態は、FrameLayout。
そして、その中にNavigationMenuViewというRecyclerViewがある。
よって、NavigationViewに対してスクロールバーを消すことはできず、NavigationMenuViewに対してスクロールバーを消すように書く必要がある。

実装

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
    if (navigationView != null) {
        NavigationMenuView navigationMenuView = (NavigationMenuView) navigationView.getChildAt(0);
        if(navigationMenuView != null) {
            navigationMenuView.setVerticalScrollBarEnabled(false);
        }
    }
}
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2