移除拇指并为禁用的寻道条设置进度色。

问题描述 投票:3回答:1

在禁用时,默认的寻道条行为是保持该条的 thumb 视觉效果,并去除进度色。我想翻转这一点,而是去掉拇指,保留进度色(虽然我想改变颜色值)。

我想,我可以使用ColorStateLists来实现对 thumbTintprogressTint 但这并不奏效。把拇指变成透明的,在条形图上留下了一个奇怪的空隙,而禁用颜色的 progressTint 始终被忽略。

当前启用状态。

Current Enabled State

当前禁用状态。

Current Disabled State

Desired Disabled State(期望的禁用状态)。

Desired Disabled State

布局。

<SeekBar
    style="@style/Zero.Seekbar.Green"
    android:id="@+id/sb_range"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toStartOf="@id/tv_range_value"
    android:progress="140"
    android:max="200"
    android:enabled="@{viewModel.rangeEnabled}"
    />

styles.xml.color_seekbar_green.xml: 样式。

<!-- SeekBar-->
<style name="Zero.Seekbar" parent="Zero">
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:paddingTop">4dp</item>
    <item name="android:paddingBottom">8dp</item>
    <item name="android:paddingStart">@dimen/gutter_width</item>
    <item name="android:paddingEnd">@dimen/gutter_width</item>
    <item name="android:progressTint">@color/zero_orange</item>
    <item name="android:progressBackgroundTint">@color/zero_gray_header</item>
    <item name="android:thumb">@drawable/slider_thumb_ride_mode</item>
    <item name="layout_constraintTop_toTopOf">parent</item>
    <item name="layout_constraintBottom_toBottomOf">parent</item>
    <item name="layout_constraintStart_toStartOf">parent</item>
</style>

<style name="Zero.Seekbar.Green" parent="Zero.Seekbar">
    <item name="android:progressTint">@color/color_seekbar_green</item>
    <item name="android:thumbTint">@color/transparent</item>
</style>

color_seekbar_green.xml。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="true"
        android:color="@color/zero_green" />
    <item android:state_enabled="false"
        android:color="@color/zero_yellow" />
</selector>
android xml kotlin seekbar
1个回答
0
投票

你可以简单地使用ProgressBar代替

© www.soinside.com 2019 - 2024. All rights reserved.