Disable changes on seekbar by client
Asked Answered
J

7

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

Joyajoyan answered 29/4, 2013 at 16:59 Comment(2)
Dupe: #4137069Chellean
Possible duplicate of How to Set an Android SeekBar to be unmoveable/frozen?Celibate
L
44

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

Laevorotatory answered 29/4, 2013 at 17:30 Comment(3)
Though you might want to include a custom drawable as setting the seekbar to disabled will change the look of the seekbar.Neither
@Arjun, I have tested what you sugest me, and it works ;) Thanks!Joyajoyan
I want the seekbar to be movable only by thumb and disable the click. how to do it ?Held
O
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;
 }
});
Obliging answered 5/1, 2015 at 11:57 Comment(2)
How would I return the default onTouch behaviours? Say if I need to enable and disable touch according to a type.Chops
kotlin answer : seekBar1.setOnTouchListener { _: View?, _: MotionEvent? -> true }Brenneman
L
44

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

Laevorotatory answered 29/4, 2013 at 17:30 Comment(3)
Though you might want to include a custom drawable as setting the seekbar to disabled will change the look of the seekbar.Neither
@Arjun, I have tested what you sugest me, and it works ;) Thanks!Joyajoyan
I want the seekbar to be movable only by thumb and disable the click. how to do it ?Held
O
2

Just return false from onTouch method of CustomSeekBar class.

Hope this works !

Overheat answered 28/6, 2016 at 9:38 Comment(0)
A
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;
     }
  });

Alissaalistair answered 14/10, 2020 at 21:44 Comment(0)
B
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)

Bridwell answered 4/11, 2022 at 5:39 Comment(1)
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.Underneath
P
0

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

Precis answered 20/7, 2023 at 11:37 Comment(0)
G
0

You can write the above code in Kotlin as shown below. Returning true will stop the movement of the thumb, while returning false will not have any effect:

seekBar.setOnTouchListener { view: View?, motionEvent: MotionEvent? -> true }
Guimpe answered 2/7 at 12:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.