how to change color of the actual scroll in Scroll

2019-03-09 16:34发布

问题:

I'm wondering if it's possible to change the color of the ScrollView.

I'm not referring to the background color or the edges.
I attached a print screen of the bar I'm referring. For me, it's kind of transparnt.

Here's how I defined it in the xml:

<ScrollView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:fadeScrollbars="false"
    android:layout_toLeftOf="@+id/personalscores_BackButton" 
    android:layout_marginRight="0dp" > 

回答1:

Create a scroll bar in drawable(scrollbar.xml) using this

<shape android:shape="rectangle"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
         android:angle="45"
         android:centerColor="#65FF8215"
         android:endColor="#87FD2125"
         android:startColor="#65FF8215" />
    <corners android:radius="20dp" />
</shape>

and add this scroll bar like android:scrollbarThumbVertical="@drawable/scrollbar" to your ListView

OR

put the following attribute to your layout

android:scrollbarThumbVertical="@android:color/white"

OR

create a image and put it in drawable. then add the following property to your layout

android:scrollbarThumbVertical="@drawable/scroll_bar_vertical"


回答2:

put the following attribute to your layout

android:scrollbarThumbVertical="@android:color/white"

or create a image and put it in drawable. then add the following property to your layout

android:scrollbarThumbVertical="@drawable/scroll_bar_vertical"


回答3:

Taken from this question:

You can set Listview property as or put the following attribute to your scrollview:

android:scrollbarThumbVertical="@drawable/custom_scroll_style"

Here custom_scroll_style is a xml file under the drawable folder. Lets create the custom_scroll_style.xml.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<gradient
android:angle="45"
android:endColor="#FF3401"
android:centerColor="#ff5c33"
android:startColor="#FF3401" />

<corners android:radius="8dp" />

</shape>


回答4:

Try this beautiful custom scrollview

Add following tags in your scrollview

    android:fadeScrollbars="false"
    android:scrollbarStyle="insideInset"
    android:scrollbarThumbVertical="@drawable/scrollview_thumb"
    android:scrollbarTrackVertical="@drawable/vertical_scrollview_track"

Create following drawable in your drawable folder

scrollview_thumb.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid android:color="@color/common_google_signin_btn_text_light_focused" />
<corners android:radius="15dp" />

</shape>

vertical_scrollview_traack.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid android:color="#E2E0EB" />
<stroke
    android:width="1dp"
    android:color="#b3a9a9" />
<size android:width="15dp" />
<corners android:radius="15dp" />
</shape>

Output