【问题标题】:Android change seekbar colorAndroid更改搜索栏颜色
【发布时间】:2020-07-20 11:08:39
【问题描述】:

我的应用中有这个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 样式的颜色定义。知道是什么问题吗?

【问题讨论】:

  • 您在哪个设备上测试过 API 级别?
  • @Raj 使用 Android 9(Samsung 8),API 级别 - 28

标签: android android-layout material-components-android android-seekbar android-slider


【解决方案1】:

使用 SeekBar,您可以使用:

   <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>

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

<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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-31
    相关资源
    最近更新 更多