android - 删除拇指并为禁用的搜索栏设置 progressTint

标签 android xml kotlin seekbar

禁用时的默认搜索栏行为是保持 thumb 可见并删除进度颜色。我想翻转它,而不是移除拇指并保持进度颜色(尽管我想更改颜色值)。

我以为我可以只对 thumbTintprogressTint 使用 ColorStateLists,但这没有用。使拇指透明在栏中留下一个奇怪的间隙,progressTint 的禁用颜色始终被忽略。

当前启用状态:

Current Enabled State

当前禁用状态:

Current 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}"
    />

样式.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>

最佳答案

您可以简单地使用 ProgressBar 代替

关于android - 删除拇指并为禁用的搜索栏设置 progressTint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51481083/

相关文章:

java - 添加到ArrayList

Android Listview 只显示一项

Android - 对 recyclerview (Firebase) 的多个查询

Android 可扩展 ListView

android - 如何通过 Kotlin 在 ListView 上获取已检查的 ID?

android - 如何使用 Kotlin 协程获取 API 错误主体

javascript - 使用 jQuery 解析包含 CDATA 的 RSS 提要

c# - 如何在 .net 反序列化期间防止 XML 外部实体 (XXE) 攻击

xml - XPath 1.0能否以类似于返回节点属性和文本的方式返回XML元素名称?

generics - 用于通用列表的 Moshi 自定义适配器 <T :Enum> returns List<List<T:Enum>> instead of List<T:Enum>