Reputation:
I have to customize scrollbar in webview - change track and thumb colors, shapes (simple rectangles). I couldn't find any information about customizing webview scrollbar, only listviews.
So far, i created:
styles.xml
<style name="CustomScrollBar">
<item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
<item name="android:scrollbarStyle">outsideOverlay</item>
<item name="android:scrollbars">vertical</item>
<item name="android:fadeScrollbars">true</item>
<item name="android:scrollbarThumbVertical">@drawable/custom_scrollbar_thumb</item>
<item name="android:scrollbarTrackVertical">@drawable/custom_scrollbar_track</item>
<item name="android:scrollbarSize">12dp</item>
<item name="android:scrollbarFadeDuration">2000</item>
<item name="android:scrollbarDefaultDelayBeforeFade">1000</item>
</style>
drawable/custom_scrollbar_track.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="0"
android:endColor="@color/gray"
android:startColor="@color/gray" />
<corners android:radius="6dp" />
</shape>
drawable/custom_scrollbar_thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="0"
android:endColor="@color/green"
android:startColor="@color/green" />
<corners android:radius="6dp" />
</shape>
However, wv.setScrollBarStyle(R.style.CustomScrollBar);
gives me an error:
Must be one of: View.SCROLLBARS_INSIDE_OVERLAY, View.SCROLLBARS_INSIDE_INSET, View.SCROLLBARS_OUTSIDE_OVERLAY, View.SCROLLBARS_OUTSIDE_INSET
Upvotes: 1
Views: 3473
Reputation:
It was easier than i thought. Just added
android:scrollbarThumbVertical="@drawable/custom_scrollbar_thumb"
android:scrollbarTrackVertical="@drawable/custom_scrollbar_track"
attributes to my webview in layout file. Of course i had to remove corners attributes from drawable files.
Upvotes: 4