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

3
我可以帮您进行翻译。以下是所需翻译的内容:

我的应用程序中有几个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>

请问您能否发布您的布局文件? - Mauker
那么你不是在使用默认的 ListView 吗?这是一个自定义库吗?你能告诉我你从哪里得到它的吗?也许这个自定义实现忽略了标志,所以才会出现问题... - Mauker
不,我定义了一个自定义的ListView,可以下拉加载更多或刷新,它继承了Android ListView。https://github.com/msdx/RefreshListView 这里是资源。 - Lemon
1个回答

2
如果XML无法正常工作,可以尝试通过编程方式隐藏它。
listview.setVerticalScrollBarEnabled(false); 
listview.setHorizontalScrollBarEnabled(false);

无论如何,xml方式应该可以正常工作...因为在文档中已经说明了。
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.
    }
});

抱歉,这是一个拼写错误,实际上应该是whiteandroid:scrollbars="none"。 - Lemon
你正在使用 ScrollView 吗? - Mauker
如果调用 isVerticalScrollBarEnabled() 会发生什么? - Mauker
1
非常感谢。现在我确定是我的自定义列表视图的问题,我会找出原因的。如果我没有任何解决办法,我会尝试你的建议,因为我在项目中有很多这样的列表视图。 - Lemon
1
非常感谢,我在我的ListView中有一个setFastScrollEnabled(true),所以XML和Java的方法都无法工作。 - Lemon
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接