在 Android 中更改滚动条颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3071068/
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
Change scrollbar color in Android
提问by pgsandstrom
Is it possible to change the color or appearance of the scrollbar in a ScrollView or ListView?
是否可以更改 ScrollView 或 ListView 中滚动条的颜色或外观?
采纳答案by adamp
Check out the ApiDemos sample project in the SDK. The layout res/layout/scrollbar2.xml
shows a way to style scroll bars.
查看 SDK 中的 ApiDemos 示例项目。该布局res/layout/scrollbar2.xml
显示了一种设置滚动条样式的方法。
There are separate attributes for the scrollbar track and the scrollbar thumb. Size can also be adjusted.
滚动条轨道和滚动条缩略图有单独的属性。大小也可以调整。
回答by Silambarasan Poonguti
You can set Listview property as
您可以将 Listview 属性设置为
android:scrollbarSize="10dp"
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" />
<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.
在这里,我得到了一个橙色滚动条。如果图像大小小于 2px 而不是 xml,您也可以使用图像。