简体   繁体   English

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

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

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

滚动条

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. 创建一个图像并将其放入drawable中。 then add the following property to your layout 然后将以下属性添加到您的布局

android:scrollbarThumbVertical="@drawable/scroll_bar_vertical"

put the following attribute to your layout 将以下属性放入您的布局

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

or create a image and put it in drawable. 或者创建一个图像并将其放入drawable中。 then add the following property to your layout 然后将以下属性添加到您的布局

android:scrollbarThumbVertical="@drawable/scroll_bar_vertical"

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_style is a xml file under the drawable folder. 这里custom_scroll_style是drawable文件夹下的xml文件。 Lets create the custom_scroll_style.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>

Try this beautiful custom scrollview 试试这个漂亮的自定义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 在drawable文件夹中创建以下drawable

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

在此输入图像描述

The question is: " how to change color "问题是:“如何改变颜色

The only correct answer is one : code line in your layout:唯一正确的答案:布局中的代码行:

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

Thats all!就这样!

ps The question is simple: "color". ps 问题很简单:“颜色”。 and the answer is very simple too: Not a, "how to set custom bar".答案也很简单:不是“如何设置自定义栏”。 "how to change bar sizes" or etc. Why so many long answers... “如何改变条形大小”等等。为什么有那么长的答案......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM