【问题标题】:Android seekbar anyway to set different style attributes byclicking a button?无论如何,Android seekbar 通过单击按钮来设置不同的样式属性?
【发布时间】:2015-12-03 04:27:09
【问题描述】:

我现在正尝试在用户单击按钮时更改搜索栏的样式。 我确实有 2 个用 XML 形成的进度可绘制对象,但是当我使用 setProgressDrawable() 函数时,它完全忽略了我在 xml 上添加的样式,只是设置了一个可绘制对象。

是否可以通过 Java 代码以编程方式更改样式?

或者是否可以在不接触样式的情况下更改次要进度的颜色? +++++++++++++++++++++++++++++++++++++++

我有两个 XML 可绘制对象。

progress_bar.xml

< layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    < item android:id="@android:id/background">
        < shape>
            < gradient 
                    android:startColor="#10ffffff"
                    android:endColor="#10ffffff"
                    android:angle="270" />                                  
    < /shape>
    < /item>
    < item android:id="@android:id/secondaryProgress">
        < clip>
           < shape>
              < gradient
                    android:startColor="#10ffffff"
                    android:endColor="#10ffffff"
                    android:angle="270" />
           < /shape>
        < /clip>
    < /item>
    < item android:id="@android:id/progress">
        < clip>
           < shape>
              < gradient
                    android:startColor="@color/C_Orange1"
                    android:endColor="@color/C_Orange1"
                    android:angle="270" />
           < /shape>

        < /clip>
    < /item>
< /layer-list>

另一个是用几乎相同的代码创建的,除了@android:id/secondaryProgress@android:id/progress的位置 称为progress_bar_timeshift.xml

< layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    < item android:id="@android:id/background">
        < shape>
            < gradient 
                    android:startColor="#10ffffff"
                    android:endColor="#10ffffff"
                    android:angle="270" />                                  
    < /shape>
    < /item>
    < item android:id="@android:id/progress">
        < clip>
           < shape>
              < gradient
                    android:startColor="@color/C_Orange1"
                    android:endColor="@color/C_Orange1"
                    android:angle="270" />
           < /shape>
        < /clip>
    < /item>
    < item android:id="@android:id/secondaryProgress">
        < clip>
           < shape>
              < gradient
                    android:startColor="#10ffffff"
                    android:endColor="#10ffffff"
                    android:angle="270" />
           < /shape>

        < /clip>
    < /item>
< /layer-list>

我有两种自定义样式

<style name="Widget.SeekBar" parent="android:style/Widget.SeekBar">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@drawable/progress_bar</item>
    <item name="android:indeterminateDrawable">@drawable/progress_bar</item>
    <item name="android:minHeight">1dp</item>
    <item name="android:maxHeight">1dp</item>
    <item name="android:thumb">@drawable/seekbar_thumb_button</item>
    <item name="android:thumbOffset">13dp</item>
    <item name="android:focusable">true</item>
</style>
<style name="Widget.SeekBar2" parent="android:style/Widget.SeekBar">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@drawable/progress_bar_timeshift</item>
    <item name="android:indeterminateDrawable">@drawable/progress_bar_timeshift</item>
    <item name="android:minHeight">1dp</item>
    <item name="android:maxHeight">1dp</item>
    <item name="android:thumb">@drawable/seekbar_thumb_button</item>
    <item name="android:thumbOffset">13dp</item>
    <item name="android:focusable">true</item>
</style>

单击按钮时,我想将Widget.SeekBar 更改为Widget.SeekBar2。是否可以? 我真正需要的是在单击按钮(不是拇指)时更改次要进度和主要进度的颜色。

++++++++++++++++++++++++++++

好的,这是图片

Original SeekBar

这是我目前拥有的第一个搜索栏。

现在,当我按下按钮时,将设置二级进度, 我想改变主要进度的颜色而不影响次要进度。

喜欢这个

wanted look

第二张图橙色部分为二次进度部分。 当我使用滤色器时,它会改变其中的所有颜色。

【问题讨论】:

    标签: android styles progress seekbar


    【解决方案1】:

    您可以使用以下库在点击事件上以编程方式更改样式:

    https://github.com/ahmedrizwan/SeekBarCompat

    【讨论】:

    • 请告诉我你想要哪种类型的搜索栏的图片?
    猜你喜欢
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    • 1970-01-01
    • 2020-01-17
    相关资源
    最近更新 更多