Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,784,212 Members 42,720 Now Online
XDA Developers Android and Mobile Development Forum

make a toggle button "greyed out"

Tip us?
 
smaskell
Old
#1  
Senior Member - OP
Thanks Meter 45
Posts: 461
Join Date: Jan 2010
Location: Victoria, BC, Canada
Default make a toggle button "greyed out"

Hey guys,
Is there anyway to disable a toggle button and make it "greyed out"? I could just make it invisible but I think it would make more sense to the user if they could see that the button was not available rather than just having it disappear. I figured this would be pretty standard but I don't see it anywhere. Any help would be greatly appreciated.

Thanks,
Samuel Maskell
Rootstonian Old
#2  
Guest
Thanks Meter 0
Posts: n/a
What's the purpose of the button?

You could just leave it there and not process based on code in the Listener.
 
smaskell
Old
#3  
Senior Member - OP
Thanks Meter 45
Posts: 461
Join Date: Jan 2010
Location: Victoria, BC, Canada
Yeah, I was thinking of just making it display a toast message or something
but it would really be nice if I could change the appearance of the button
maybe I can play around with changing the background a bit..
 
Gene Poole
Old
#4  
Recognized Contributor
Thanks Meter 551
Posts: 1,667
Join Date: Jul 2010
Location: Brighton IL
Why not just setEnabled(false); ?
 
smaskell
Old
#5  
Senior Member - OP
Thanks Meter 45
Posts: 461
Join Date: Jan 2010
Location: Victoria, BC, Canada
so I tried just using setBackgroundColor(Color.DKGRAY) but that failed miserably..
I can use getBackground() to get a Drawable object
so I should be able to take that object and make it darker
and then use setBackgroundDrawable, right?
I'm just not too sure how to go about making that drawable darker..
 
smaskell
Old
#6  
Senior Member - OP
Thanks Meter 45
Posts: 461
Join Date: Jan 2010
Location: Victoria, BC, Canada
Quote:
Originally Posted by Gene Poole View Post
Why not just setEnabled(false); ?
Didn't see your post last time. I am using setEnabled(false), but this does not change the appearance of the button. How are users supposed to know that the button is disabled? They'll just press it and think that the application froze or something because nothing will happen. If I could make the button darker and disable it, I think people would get the idea that it is disabled and not just broken.

Thanks,
Sam
 
smaskell
Old
(Last edited by smaskell; 28th February 2011 at 07:38 PM.)
#7  
Senior Member - OP
Thanks Meter 45
Posts: 461
Join Date: Jan 2010
Location: Victoria, BC, Canada
apparently the background isn't what I want to change. Not sure what I should be doing exactly..
 
freekyfrogy
Old
(Last edited by freekyfrogy; 28th February 2011 at 08:17 PM.)
#8  
freekyfrogy's Avatar
Senior Member
Thanks Meter 21
Posts: 366
Join Date: Aug 2009
Location: Virginia
have you tried toggle.setColorFilter(0xAARRGGBB, Mode.SRC_ATOP); ?

you'd need to find the correct #AARRGGBB code for a greyish color, but it should work.

EDIT: Ok, so after playing around with the settings a bit I found that this works pretty nicely for greying something out toggle.setColorFilter(0xA6A6A6A6, Mode.SRC_ATOP);
As of 8/1/2014:

Current Phone: Nexus 5
ROM: Omni ROM

Current Tablet: Asus TransformerTF300
ROM: Paranoid Android

Current Watch: LG G Watch
ROM: Stock

follow me on twitter and I'll give you a cookie!
Make sure to click the "Thanks" button if you like what I do! It helps my ego
The Following User Says Thank You to freekyfrogy For This Useful Post: [ Click to Expand ]
 
smaskell
Old
#9  
Senior Member - OP
Thanks Meter 45
Posts: 461
Join Date: Jan 2010
Location: Victoria, BC, Canada
ToggleButton doesn't seem to have a setColorFilter() class
did you do toggle.getBackground.setColorFilter() or something like that?
 
freekyfrogy
Old
#10  
freekyfrogy's Avatar
Senior Member
Thanks Meter 21
Posts: 366
Join Date: Aug 2009
Location: Virginia
Actually, I was using setColorFilter on an ImageButton, that's probably why... sorry :P
As of 8/1/2014:

Current Phone: Nexus 5
ROM: Omni ROM

Current Tablet: Asus TransformerTF300
ROM: Paranoid Android

Current Watch: LG G Watch
ROM: Stock

follow me on twitter and I'll give you a cookie!
Make sure to click the "Thanks" button if you like what I do! It helps my ego

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Prevent Apps from Locking Screen Orientation with HaveOwnOrientation

Most applications on Android play nicely with both landscape and … more

Create Your Own Launcher with HTMLauncher

There are hundreds of launcher replacement applications available for Android. Most of them are … more

First ROMs Appear for the Nvidia Shield Tablet

TheNvidia Shield Tablethas only been available for a little over a month. In that short time, … more

How to Root the LG G Watch – XDA Developer TV

In this episode, XDA Developer TV Producer RootJunky Tom shows you how to root and unlock … more