【问题标题】:Change Android 5.0 scrollbar color更改 Android 5.0 滚动条颜色
【发布时间】:2014-11-18 15:55:30
【问题描述】:
有谁知道如何将 Theme.Material 中滚动条的颜色更改为 colorControlNormal 以外的颜色?如果你去查看themes_material你可以看到有一些滚动条属性,但是没有直接的方法来覆盖滚动条的颜色,只有整个drawable。出于我的目的,我想保持可绘制的滚动条与系统正在使用的滚动条相同(相同的九个补丁),我只想将其着色为与我的 colorControlNormal 颜色不同的颜色。
【问题讨论】:
标签:
android
android-5.0-lollipop
material-design
【解决方案1】:
我发现您可以将您自己主题中的整个 scrollbarThumbVertical 或 scrollbarThumbHorizontal 属性覆盖为不同的可绘制对象;在您的 AppTheme 中,它看起来像:
<style name="AppTheme" parent="@android:style/Theme.Material">
<item name="android:scrollbarThumbVertical">@drawable/scrollbar_handle_material</item>
</style>
然后在您的 drawable-v21 文件夹中,您将在此处从系统中找到相同的 xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/scrollbar_handle_mtrl_alpha"
android:tint="#A4A4A4" />
您可以将色调颜色设置为您希望滚动条在 5.0+ 设备上显示的颜色。由于 Google 不会公开 scrollbar_handle_mtrl_alpha 资产以供访问,因此您需要从 PATH_TO_ANDROID_SDK/platforms/android-21/data/res/drawable-xxhdpi/scrollbar_handle_material_alpha 以及您要提供的所有其他密度中提取它。我将drawable-xxhdpi资源放在这里供参考:
如果你们找到任何其他方法来做到这一点而不必覆盖这么多东西,请告诉我。