没有滚动条的android drawerLayout(SlideMenu)

标签 android android-navigationview

我有一个带有侧边菜单的 android 应用程序(默认的 android Activity 抽屉导航 Activity )

我想隐藏滚动条。 我为此使用了这段代码:

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setVerticalScrollBarEnabled(false);
    navigationView.setHorizontalScrollBarEnabled(false);

但是滚动条并没有被隐藏。 为什么不呢?

XML

<?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">


    <android.support.design.widget.CoordinatorLayout
        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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context="x.Overview">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </android.support.design.widget.AppBarLayout>



        <android.support.v4.view.ViewPager
            android:id="@+id/page_adapter"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />


    </android.support.design.widget.CoordinatorLayout>
    <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"
        android:gravity="bottom"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:theme="@style/ThemeOverlay.AppCompat.Light"
        app:menu="@menu/sidebar"/>

</android.support.v4.widget.DrawerLayout>

最佳答案

您可以在您的主题样式中使用以下代码为滚动条设置透明颜色。

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

然后将自定义主题添加到您的导航 View 。

<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:menu="@menu/activity_main_drawer"
        app:theme="@style/YOUR.THEME"
         />

关于没有滚动条的android drawerLayout(SlideMenu),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33933101/

相关文章:

java - FingerPaint 删除显示黑线

android - 导航 View 的选择器行为不正确

android - Home Fragment 部分可见,当前 Fragment Android Studio 的混合 View

android - Material 设计中的底部抽屉

android - 如何删除导航 View 不必要的顶部填充?

android - 不从导航 View 中突出显示选定的子项

android - 无法连接远程调试器

Android Studio Vector Asset 导入错误 - 不支持标签

android - 如何在 Android 中将 XML 文件从 http 解析为 SQLite

android - 如何制作类似于 Gmail 或 G+ 的 "progressbar"?