有谁知道如何将 Theme.Material 中滚动条的颜色更改为 colorControlNormal 以外的颜色?如果您查看主题 Material ,您可以看到存在某些滚动条属性,但没有直接的方法可以覆盖滚动条颜色,只能覆盖整个可绘制对象。出于我的目的,我希望保持滚动条的可绘制性与系统使用的滚动条相同(相同的 9-patch ),我只想将其着色为与我的 colorControlNormal 颜色不同的颜色。
最佳答案
我发现您可以将自己主题中的整个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 Assets 公开以供访问,因此您需要从 PATH_TO_ANDROID_SDK/platforms/android-21/data/res/drawable-xxhdpi/scrollbar_handle_material_alpha 中提取它以及您想要提供的所有其他密度。我将把drawable-xxhdpi资源放在这里以供引用:
如果你们找到任何其他方法来做到这一点,而不必覆盖这么多事情,请告诉我。
关于android - 更改Android 5.0滚动条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26998457/