1

我的应用程序中有这个SeekBar

<SeekBar
        android:id="@+id/volume_seek_bar"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:theme="@style/Volume_Seekbar" />

这是样式文件:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/toolbar_background</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="ProgressBarStyle">
    <item name="colorAccent">@color/colorPrimary</item>
</style>

<style name="Volume_Seekbar">
    <item name="colorPrimary">@color/app_blue</item>
    <item name="colorPrimaryDark">@color/toolbar_background</item>
    <item name="colorAccent">@color/app_blue</item>
</style>

我想使用样式来更改颜色,SeekBar但它一直从AppTheme样式中获取颜色定义。知道有什么问题吗?

4

1 回答 1

1

使用 aSeekBar您可以使用:

   <SeekBar
        android:theme="@style/MySeekBar"
        />

和:

<style name="MySeekBar">
    <item name="android:progressBackgroundTint">@color/....</item>
    <item name="android:progressTint">@color/...</item>
    <item name="android:colorControlActivated">@color/....</item>
</style>

在此处输入图像描述 在此处输入图像描述

现在您还可以使用SliderMaterial Components Library 提供的新组件:

<com.google.android.material.slider.Slider
       android:valueFrom="0"
       android:valueTo="300"
       android:value="200"
       android:theme="@style/slider_red"
       />

您可以使用以下内容覆盖默认颜色:

  <style name="slider_red">
    <item name="colorPrimary">#......</item>
  </style>

在此处输入图像描述

注意: Slider需要1.2.0材料组件的版本。

于 2020-07-20T11:28:59.193 回答