如何在Android中更改滚动条的颜色? [英] How can I change the color of the scrollbar in Android?

查看:576
本文介绍了如何在Android中更改滚动条的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前问题是我们的主题继承自Theme.AppCompat,该主题似乎具有白色滚动条,并且在白色背景上不可见. 我知道我可以使用

<item name="android:scrollbarThumbVertical">@drawable/scroll_thumb</item>

并为自定义滚动条创建形状.但我只想将其更改为较深的颜色.当我使用简单的彩色矩形形状时,它的宽度与普通滚动条的宽度不同.

这可能吗?

解决方案

好,可以为scrollbarThumbVertical项目值使用颜色,但这会改变宽度,因此我将大小设置为4dp,即

似乎与其他带有原生滚动条的视图相同

    <item name="android:scrollbarSize">4dp</item>
    <item name="android:scrollbarThumbVertical">@color/scrollbar_thumb</item>

我不想设置尺寸,但是我看不到其他更干净的方法.

The current problem is that our theme is inheriting from Theme.AppCompat, which appears to have a white scrollbar, and that is not visible on the white background. I know that I can use

<item name="android:scrollbarThumbVertical">@drawable/scroll_thumb</item>

And create a shape for the custom Scrollbar. But I only want to change it to a darker color. When I use a simple colored rectangle shape, it has a different width than the normal scrollbar.

Is this possible?

解决方案

ok, it is possible to use a color for the scrollbarThumbVertical item value, but this will change the width, so I set the size to 4dp, which

seems to be the same as in the other views with the native scrollbars

    <item name="android:scrollbarSize">4dp</item>
    <item name="android:scrollbarThumbVertical">@color/scrollbar_thumb</item>

I don't like having to set the size, but I don't see any other way that would be cleaner.

这篇关于如何在Android中更改滚动条的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆