Android disabled search bar without dimming

I need to prevent searches from user inputs in special cases. If I use setEnabled (false) instead of gray, instead of white.

Is there any method for disabling the search character without dimming or setting another resource to progress in the disabled search bar?

+4
source share
5 answers

I am not sure why you want to change this, and I do not believe that it is good practice to redefine the visual queue for the user that something is disabled. If it looks active, but does not interact, I will be mad at your application.

Regardless of how you answer your question, you should look at the StateListDrawable question that describes this specifically for search bars.

+2
source

Yes. Maybe! But you need to override the SeekBar drawableStateChanged function, with something like this:

@Override protected void drawableStateChanged() { super.drawableStateChanged(); final Drawable progressDrawable = getProgressDrawable(); if(isEnabled() == false && progressDrawable != null) progressDrawable.setAlpha(255); } 

In fact, I got really angry when I saw the value of hardcoded alpha in AbsSeekBar:

 mDisabledAlpha = a.getFloat(com.android.internal.R.styleable.Theme_disabledAlpha, 0.5f); 

Because there is no function that will turn off or even change the alpha value for SeekBar. Just take a look at these lines of code in the drawableStateChanged function:

 if (progressDrawable != null) { progressDrawable.setAlpha(isEnabled() ? NO_ALPHA : (int) (NO_ALPHA * mDisabledAlpha)); } 
+4
source

The best solution is here ....

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

Android changes the alpha value of the color to 127 out of 255 in the disabled state. Just make sure you set it back to 255 after disabling the search.

 seekBar.post(new Runnable(){ @Override public void run() { seekBar.getProgressDrawable().setAlpha(255); } }); 

view.post is only required if you are not sure if the search bar is displayed or not, otherwise it’s just

 seekBar.getProgressDrawable().setAlpha(255); 

.

0
source

You can use setEnabled (false) and set the Theme_disabledAlpha attribute as @Ilya Pikin mentioned above:

  <item name="android:disabledAlpha">1.0</item> 
0
source

All Articles