0

I'm writing an app which uses seekbars to control volume. I wanted the seekbars to be thicker, so I implemented a custom seekbar based on: Android - How to change default SeekBar thickness?

Everything works great, except now when I want to disable the control, it disables the functionality, but doesn't change the look of it visually. Before applying the custom seekbar, disabling the control would make it turn grey so the user knew it was disabled.

Does anyone know what custom control I must not be styling?

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@android:id/background">
    <shape
        android:shape="line">
      <stroke
          android:color="@color/seek_bar_background"
          android:width="@dimen/seek_bar_thickness"/>
    </shape>
  </item>

  <item android:id="@android:id/progress">
    <clip>
      <shape
          android:shape="line">
        <stroke
            android:color="@color/seek_bar_progress"
            android:width="@dimen/seek_bar_thickness"/>
      </shape>
    </clip>
  </item>

  <item android:id="@android:id/secondaryProgress">
    <clip>
      <shape
          android:shape="line">
        <stroke
            android:color="@color/seek_bar_secondary_progress"
            android:width="@dimen/seek_bar_thickness"/>
      </shape>
    </clip>
  </item>
</layer-list>

There must be some kind of <item android:id="@android:id/disabled"> property? I've looked but can't find anything, and everyone else styling seekbars doesn't seem to use any other item properties.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
user3704961
  • 1
  • 1
  • 2

1 Answers1

0

I have been able to achieve this by using a selector.

Basically, my axml file which uses the seekbar element calls

android:progressDrawable="@menu/seek_style_selector"
android:thumb="@menu/seek_thumb_selector"

and these selectors are two new files which implement the item android:state_enabled="false"

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_enabled="false" android:drawable="@menu/seek_disabled"></item>
    <item android:drawable="@menu/seek">   
  </item>
</selector>

So if it is disabled, it will use the seek_disabled file, which has different opacities for the elements. Otherwise, it will continue to use the normal seek file.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
user3704961
  • 1
  • 1
  • 2