如何使用 AppCompat 样式隐藏 Listview 的滚动条

How to hide Listview's ScrollBars with AppCompat Style

我的app里有好几个ListViews,每个人写的代码都差不多,但有的有ScrollBar,有的都有android:scrollBars = "none",都不行。

那么问题是什么?如何隐藏滚动条?

布局文件:

 <com.zuanbank.android.widgets.RefreshListView 
  android:id="@+id/list_view"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@color/main_bg"
  android:orientation="vertical"
  android:scrollbars="none"
  app:init_footer="true"
  app:init_header="false">

</com.zuanbank.android.widgets.RefreshListView>

我的风格:

 <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">   </style>

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowAnimationStyle">@style/activityAnimation</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowBackground">@null</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorControlNormal">@color/blue_00a0ea</item>
    <item name="colorControlActivated">@color/colorControlActivated</item>
    <item name="colorSwitchThumbNormal">@color/blue_00a0ea</item>
</style>

如果 xml 不起作用,请尝试以编程方式隐藏它。

listview.setVerticalScrollBarEnabled(false); 
listview.setHorizontalScrollBarEnabled(false);

无论如何,xml 方法应该有效...正如 the docs 中所述。

android:scrollbars="none"

编辑: 看起来,您没有使用默认 ListView。一种选择是让您回滚到默认实现,并将其包装在 SwipeRefreshLayout.

周围

像这样:

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/srl_refresh">
    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/lv_data"
        android:choiceMode="singleChoice"
        android:scrollbars="none" />
</android.support.v4.widget.SwipeRefreshLayout>

然后在您的 FragmentActivity 上执行此操作:

srl_refresh = (SwipeRefreshLayout) rootView.findViewById(R.id.srl_refresh);
srl_refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {
        doRefresh(); // Call your refresh method here.
    }
});