简体   繁体   English

Android 更改搜索栏颜色

[英]Android change seekbar color

I have this SeekBar in my app:我的应用中有这个SeekBar

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

And this is the style file:这是样式文件:

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

I want to use the style to change the color of the SeekBar but it keeps taking the color definition from the AppTheme style.我想使用该样式来更改SeekBar的颜色,但它一直从AppTheme样式中获取颜色定义。 Any idea what is the problem?知道有什么问题吗?

With a SeekBar you can use:使用SeekBar ,您可以使用:

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

with:和:

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

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

Now you can also use the new Slider components provided by the Material Components Library:现在您还可以使用材料组件库提供的新Slider组件:

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

You can override the default color using something like:您可以使用以下内容覆盖默认颜色:

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

在此处输入图像描述

Note: Slider requires the version 1.2.0 of the Material Components.注意: Slider需要材料组件的1.2.0版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM