Lemon
Lemon

Reputation: 487

How to hide Listview's ScrollBars with AppCompat Style

I have several ListViews in my apps, and I write almost the same code in everyone, but some have ScrollBar, they all have android:scrollBars = "none" and it does not work.

So what is the problem? How can I hide the ScrollBars?

layout file:

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

And my style:

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

Upvotes: 3

Views: 774

Answers (1)

Mauker
Mauker

Reputation: 11497

If the xml is not working, try to hide it programmatically.

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

Anyways, the xml way should be working... As it's stated on the docs.

android:scrollbars="none"

Edit: As it seems, you're not using the default ListView. One option would be for you to rollback to the default implementation, and wrap it around the SwipeRefreshLayout.

Like this:

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

Then on your Fragment or Activity, do this:

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.
    }
});

Upvotes: 2

Related Questions