【问题标题】:Change ListView's ScrollBar/FastScroll color?更改 ListView 的 ScrollBar/FastScroll 颜色?
【发布时间】:2015-08-15 01:56:43
【问题描述】:

我的应用程序有一个橙色的主题,但 ScrollBar/FastScroll 显示为绿色。我尝试了很多搜索,但找不到任何方法来改变这一点。它只是保持原样。

我找到了一个“android:fastScrollTextColor”属性,但这会改变气泡内 B 的颜色。而且我找不到任何属性来更改此气泡或旁边的 ScrollBar 的颜色。

如果有什么不同,我将使用从 here 获得的自定义 PinnedHeaderListView 来模仿棒棒糖联系人应用程序中的粘性标题。

【问题讨论】:

  • 滚动条拇指颜色设置为主题中的colorAccent 属性,我相信。你确定设置是正确的,对吧?
  • 成功了。哇,我什至不知道有一种叫做强调色的东西。我以为只有 PrimaryColor 和 PrimaryColorDark。我是新来的。感谢您的帮助.. :)
  • 嘿如何在列表视图中实现这个?

标签: android android-listview material-design


【解决方案1】:

android:scrollbarThumbVertical 可以正常工作。但是如果在listView 中启用了快速滚动,您应该在AppTheme 或任何主题中定义android:fastScrollThumbDrawable,并将其用于包含启用了快速滚动的列表视图的活动(在AndroidManifest)。

styles.xml的一部分

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:fastScrollThumbDrawable">@drawable/fast_scrollbar_vertical</item>
</style>

清单的一部分

    <activity
        android:name=".ListActivity"
        android:label="@string/title_activity_list"
        android:theme="@style/AppTheme" />

并且可绘制的滚动条应该是渐变的

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<gradient
    android:angle="45"
    android:endColor="@color/scroll_color"
    android:centerColor="@color/scroll_color"
    android:startColor="@color/scroll_color" />

<corners android:radius="8dp" />
<size android:width="8dp" android:height="100dp"/>
<padding
    android:left="0.5dp"
    android:right="0.5dp" />

</shape>

【讨论】:

    【解决方案2】:

    滚动条拇指颜色设置为您的应用主题中的android:colorAccent 属性。您确定设置是正确的,对吗?

    请注意,如果您使用 AppCompat,则必须从属性中排除 android: 前缀。

    您可以找到更多关于可用颜色属性的信息here

    【讨论】:

      【解决方案3】:

      在 xml 文件中的 listView 属性中设置此项。

      android:scrollbarSize="10dp"
      android:scrollbarThumbVertical="@drawable/custom_scroll_style"
      

      这里custom_scroll_style是drawable文件夹下的一个xml文件。让我们创建 custom_scroll_style.xml

      <shape xmlns:android="http://schemas.android.com/apk/res/android" >
      
      <gradient
          android:angle="45"
          android:endColor="@color/endColor" //define what you want
          android:centerColor="@color/centercolor"
          android:startColor="@color/startColor" />
      
      <corners android:radius="8dp" />
      <size android:width="4dp"/>
      <padding
          android:left="0.5dp"
          android:right="0.5dp" />
      
      </shape>
      

      希望对你有帮助!

      【讨论】:

      • 试过了..还是一样。没有效果.. :(
      • 这工作 100% 由我测试...无论如何.. 看看你的项目...会有一些改变它...会有一些 .xml 布局文件呈现那个东西.你只需要找到它并改变它。
      • 成功了。这是我的错误,我没有设置强调色.. 感谢您的帮助!
      • 有没有办法从 java 端/以编程方式设置 android:scrollbarThumbVertical="@drawable/custom_scroll_style"?我有一个自定义 listView 并且在 Focus 上我希望它改变滚动条的颜色。
      猜你喜欢
      • 2022-01-05
      • 2012-02-16
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      • 2012-06-19
      • 2011-09-25
      • 1970-01-01
      • 2017-02-04
      相关资源
      最近更新 更多