3

I need to remove scrollbars from the complete application. I want to avoid the trouble of writing android:scrollbars="none" in all the ScrollViews defined in my application.

Now, here is what I have tried to do :

styles.xml

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:scrollViewStyle">@style/NoScrollbars</item>
        <item name="android:scrollbarStyle">@style/NoScrollbars</item>
    </style>


<style name="NoScrollbars" parent="android:Widget.ScrollView">
    <item name="android:scrollbars">none</item>
</style>

Is there any way to make this happen ?

Suraj Makhija
  • 1,376
  • 8
  • 16
  • 1
    I believe there isn't straightforward way to do that. You have to override all the styles(listview, dropdown listview, webview, preference screen, recyclerview...) manually disabling scrollbars. – azizbekian May 02 '17 at 11:11

1 Answers1

0

You can define a ScrollViewStyle and ListViewStyle in your Theme:

<style name="Theme.MyTheme" parent="android:Theme.Holo">
    <item name="android:listViewStyle">@style/Widget.MyTheme.ListView</item>
    <item name="android:scrollViewStyle">@style/Widget.MyTheme.ScrollView</item>
</style>

<style name="Widget.MyTheme.ListView" parent="android:Widget.ListView">
    <item name="android:overScrollMode">never</item>
    <item name="android:scrollbars">none</item>

</style>

<style name="Widget.MyTheme.ScrollView" parent="android:Widget.ScrollView">
    <item name="android:overScrollMode">never</item>
    <item name="android:scrollbars">none</item>

</style>

Then you have to define your Theme in you AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="nouman.app.example"
      android:versionCode="1"
      android:versionName="1.0">

<uses-sdk android:targetSdkVersion="16" android:minSdkVersion="8"/>

<application
        android:hardwareAccelerated="true"
        android:label="@string/app_name"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/Theme.MyTheme">

That's it. Done.

Nouman Ghaffar
  • 3,780
  • 1
  • 29
  • 37