简体   繁体   English

在Android中更改滚动条颜色

[英]Change scrollbar color in Android

是否可以在ScrollView或ListView中更改滚动条的颜色或外观?

You can set Listview property as 您可以将Listview属性设置为

android:scrollbarSize="10dp"
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" />
<size android:width="4dp"/>
<padding
    android:left="0.5dp"
    android:right="0.5dp" />

</shape>

Here I got a Orange color scrollbar. 在这里,我有一个橙色滚动条。 You can use images also if the image size is less than 2px instead of xml. 如果图像大小小于2像素而不是xml,也可以使用图像。

Check out the ApiDemos sample project in the SDK. 查看SDK中的ApiDemos示例项目。 The layout res/layout/scrollbar2.xml shows a way to style scroll bars. 布局res/layout/scrollbar2.xml显示了一种滚动条样式的方法。

There are separate attributes for the scrollbar track and the scrollbar thumb. 滚动条轨道和滚动条滑块有单独的属性。 Size can also be adjusted. 尺寸也可以调整。

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

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