如何在 ScrollView android 中更改实际滚动的颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20781788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:26:43  来源:igfitidea点击:

how to change color of the actual scroll in ScrollView android?

androidandroid-layoutscrollviewandroid-xml

提问by dusm

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

我想知道是否可以更改 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:

这是我在 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" > 

scroll bar

滚动条

回答by Adhikari Bishwash

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

使用这个在 drawable(scrollbar.xml) 中创建一个滚动条

<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

并将此滚动条添加android:scrollbarThumbVertical="@drawable/scrollbar"到您的 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

创建一个图像并将其放入 drawable 中。然后将以下属性添加到您的布局

android:scrollbarThumbVertical="@drawable/scroll_bar_vertical"

回答by Dehan Wjiesekara

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"

回答by M D

Taken from this question:

取自这个问题

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

您可以将 Listview 属性设置为或将以下属性添加到您的滚动视图:

android:scrollbarThumbVertical="@drawable/custom_scroll_style"

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

这里custom_scroll_style是drawable文件夹下的一个xml文件。让我们创建 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>

回答by Ranjith Kumar

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

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

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

输出

enter image description here

在此处输入图片说明