33

I have a SeekBar that will change the progress when I require it to, but I don't want the user to be able to change it manually.

I tried to set the SeekBar as this:

<SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="78dp"
        android:progress="10"
        android:max="100"
        android:clickable="false"
        android:thumb="@drawable/transparent"
        android:progressDrawable="@drawable/customprogressbar" />

But it doesn't work.

How can I do this?


That's more or less an example of how this is going to be seen by the client.

I used a custom style because in the future I'll need to change the background images and the progress depending on which section the SeekBar will be.

Thanks for all!

No given description by asker

Shudy
  • 7,806
  • 19
  • 63
  • 98
  • Dupe: http://stackoverflow.com/questions/4136569/how-to-set-an-android-seekbar-to-be-unmoveable-frozen – greg7gkb Jan 10 '14 at 02:58
  • Possible duplicate of [How to Set an Android SeekBar to be unmoveable/frozen?](http://stackoverflow.com/questions/4136569/how-to-set-an-android-seekbar-to-be-unmoveable-frozen) –  Feb 25 '17 at 16:57

6 Answers6

72

You can use android:enabled="false" , but it will display disable effect [darken your seekbar].

So if you want to display enable seekbar with no response to thumb activity, implement touch event handler with return true as shown below.

seekBar.setOnTouchListener(new OnTouchListener(){
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    return true;
 }
});
Srikanth P
  • 1,506
  • 14
  • 12
43

One thing you can do is to disable the seekbar, Like seekbar.setEnabled(false)

doing so framework will not accept any Touch event from user and you Can change progress level only through code.

I hope this will help you.......

Fedor
  • 43,261
  • 10
  • 79
  • 89
Arjun Vekariya
  • 966
  • 7
  • 8
2

Just return false from onTouch method of CustomSeekBar class.

Hope this works !

0

So if you want to display enable seekbar with no response to thumb activity, implement touch event handler with return true as shown below.

  seekBar.setOnTouchListener(new OnTouchListener()
  {
     @Override
     public boolean onTouch(View v, MotionEvent event) 
     {
        return true;
     }
  });

0

One thing you can do is to disable the seekbar, Like kotlin

val pro = popupContent.findViewById(R.id.penoptionsizeslider)

//now disable it here

pro.setEnabled(false)

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 08 '22 at 02:55
0

You can use seekbar.isEnabled = false to disable seekbar. It worked for me

MBR
  • 1
  • 1