【问题标题】:how to change color of the actual scroll in ScrollView android?如何更改 ScrollView android 中实际滚动的颜色?
【发布时间】:2013-12-26 08:43:43
【问题描述】:

我想知道是否可以更改 ScrollView 的颜色。

我指的不是背景颜色或边缘。
我附上了我所指的酒吧的打印屏幕。对我来说,这有点透明。

这是我在 xml 中定义它的方式:

<ScrollView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:fadeScrollbars="false"
    android:layout_toLeftOf="@+id/personalscores_BackButton" 
    android:layout_marginRight="0dp" > 

【问题讨论】:

    标签: android android-layout scrollview android-xml


    【解决方案1】:

    使用这个在drawable(scrollbar.xml)中创建一个滚动条

    <shape android:shape="rectangle"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient
             android:angle="45"
             android:centerColor="#65FF8215"
             android:endColor="#87FD2125"
             android:startColor="#65FF8215" />
        <corners android:radius="20dp" />
    </shape>
    

    并将此滚动条(如 android:scrollbarThumbVertical="@drawable/scrollbar")添加到您的 ListView

    将以下属性添加到您的布局中

    android:scrollbarThumbVertical="@android:color/white"
    

    创建一个图像并将其放入drawable中。然后将以下属性添加到您的布局中

    android:scrollbarThumbVertical="@drawable/scroll_bar_vertical"
    

    【讨论】:

    • 我不明白如何使用您提供的 xml 代码。那应该是整个 xml 文件吗?
    • 谢谢!这正是我想要的。 Mike,这是一个完整的 xml 文件,这是使用它的确切方法: schemas.android.com/apk/res/android">
    • @dusm ahhh 就像其他答案一样。好问题。
    • 哇...惊人的解决方案!非常感谢
    【解决方案2】:

    将以下属性添加到您的布局中

    android:scrollbarThumbVertical="@android:color/white"
    

    或创建一个图像并将其放入可绘制对象中。然后将以下属性添加到您的布局中

    android:scrollbarThumbVertical="@drawable/scroll_bar_vertical"
    

    【讨论】:

    • 你知道如何改变滚动条的粗细吗?
    • 在 ICE_CREAM_SANDWICH 上直接使用颜色对我有用,但在 GINGERBREAD 上却不行。对于 GINGERBREAD,我必须按照 Adhikari 的回答中的描述定义一个可绘制对象,并将形状包装在 中。 schemas.android.com/apk/res/android">
    • 这真的很有帮助! tysm
    【解决方案3】:

    取自this question

    您可以将 Listview 属性设置为或将以下属性设置为您的滚动视图:

    android:scrollbarThumbVertical="@drawable/custom_scroll_style"
    

    这里的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" />
    
    </shape>
    

    【讨论】:

    • 你知道如何改变滚动条的粗细吗?
    • @mike yaworski 这个链接可能对你有帮助:custom-scrollbar-graphics-in-android
    • @mikeaworski 你可以使用 android:scrollbarSize 来改变垂直滚动条的宽度和水平滚动条的高度。
    【解决方案4】:

    试试这个漂亮的自定义滚动视图

    在滚动视图中添加以下标签

        android:fadeScrollbars="false"
        android:scrollbarStyle="insideInset"
        android:scrollbarThumbVertical="@drawable/scrollview_thumb"
        android:scrollbarTrackVertical="@drawable/vertical_scrollview_track"
    

    在您的可绘制文件夹中创建以下可绘制对象

    scrollview_thumb.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    
    <solid android:color="@color/common_google_signin_btn_text_light_focused" />
    <corners android:radius="15dp" />
    
    </shape>
    

    vertical_scrollview_traack.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    
    <solid android:color="#E2E0EB" />
    <stroke
        android:width="1dp"
        android:color="#b3a9a9" />
    <size android:width="15dp" />
    <corners android:radius="15dp" />
    </shape>
    

    输出

    【讨论】:

      【解决方案5】:

      问题是:“如何改变颜色

      唯一正确的答案是一个!布局中的代码行:

      android:scrollbarThumbVertical="@android:color/white"
      

      就是这样!

      附言 问题很简单:“颜色”!答案也很简单。 不是:“如何设置自定义栏”、“如何更改栏大小”等。 为什么这么长的答案...

      【讨论】:

      • 这与the accepted answer(第二个示例)中的解决方案相同。
      • 问题很简单,答案很简单!简单 - 不需要任何第二个或第三个示例。我不想也不需要阅读所有这些变体。只需一行代码 - 全部。
      猜你喜欢
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-17
      • 2011-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多