Android Custom Buttons: Alternative to Multiple Graphics? - android

I think all custom button tutorials I have been able to find for Android assume you are using three images for your button: a normal image, a pressed image, and a focused image.
Instead of essentially tripling the size of a given button's resources (and creating more work for the artist/UX guy), is it possible to only supply a normal button image, and for the other states, draw some sort of overlay over the existing button by extending the Button class?
Has anybody tried doing this with any success, or is it just accepted that all custom buttons need an image for each state and that is that?

You could by overriding the draw methods of the view in your custom button but it would be a simple process as you would have to also identify the different states yourself.

I think the correct answer to this question is essentially what #Luksprog said in the comments... It simply isn't worth it. Just make the extra art.

Related

Button invisble but enabled

i designed my whole activity page in photoshop and opened it in eclipse.I want to put buttons on my fake image buttons. Doesnt it make any problem? I use the code below to make the button invisible but it disables button too. How can i fix this problem?
android:visibility="invisible"
You should not do like that (having a fake ImageButton on a View you want to make clickable), as many error can occur with doing it. Assuming you are trying to put this button on a whole ImageView, or a whole Layout, or at least a whole view, you should consider adding a click listener to this view. Try to find more information about how to use the View.setOnClickListener(View.OnClickListener) method. You will have less error to debug with it.
But if you still want to do, try instead using android:alpha property:
android:alpha="0"
It will make the button become invisible, but still present, and still active
This android:alpha attribute allows you to specify an opacity value for a color.
To be honest you shouldn't be doing that unless you are testing something or prototyping. Instead, you should cut your design in photoshop and export the images for your buttons.
Your approch will most likely cause the buttons to be positioned incorrectly above the image when run on different devices with different screen sizes.
The correct way to do this would be to use the ImageButton view with a StateListDrawable set as the source image.
You can read more about State Lists here:
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
It's very easy to declare it in XML and have different images for various button states (pressed, disabled, focused, ...).
To sum it all up. I would do the following things:
Export images for my buttons in all the different states that you prepared (i find neutral and pressed as an absolute minimum).
Import them as drawables in your project (be sure to generate different versions for every screen density you want to support).
Create a State List Drawable XML Resource as described here.
Set the resource created in step 3 as the android:src property of your ImageButton (setImageResource(int)).
Try android:background="#null" for your button. It will make that default gray background disappear, making your button invisible but still allowing you to add text etc if you want to.
That being said: I would not recomment a button here. I would prefer Pauls answer in your particular case.

draw multiple texts on button for android,inner-shadow

I need a way to draw multiple texts for a button in android..
I would like to simply just extend the default android button with the possibility to have an aditional text that should be overlapped by another text to create sort of a very "intense" inner-shadow effect.
The idea as mentioned is to simply extend the default button and override the onDraw-function and then draw a new text at the same position as the "default-text" for the button.. the problem is that I have no idea about how Im supposed to get the location of the "default-text" for the button..
Any ideas?
You don't have to use multiple views to create this effect. I wrote a blog post awhile back about using EmbossMaskFilter to apply this effect to a TextView. Button is just a glorified TextView, so you can use the same approach to modify its display text through a simple subclass:
http://wiresareobsolete.com/wordpress/2012/04/textview-inner-shadows/
One thing to keep in mind is that this filter is not yet supported by hardware acceleration, so you may need to draw this view on a software layer if the rest of your app takes advantage of acceleration on newer devices (if you don't know whether or not it is, by default it probably is).

How to implement this Android layout?

At the top there is the favorites/styles/all channels
i don't know what that widget/control is i need to know what it is
i am certain i saw it before i just can't seem to find it again.
then there is a listview which is easy to implement no help needed there
then the same control again, i need to know how to build it.
it looks like a native Android control, i know how i can make one just like it using image buttons but i am sure i am missing something.
P.S. this is an image from sky.fm app on android
EDIT: I Do no need help with the ListView i already did that
What i do need help with is how to make the "favorites/styles/all channels" buttons if there is a way to do natively.
If there isn't a way to do natively, and you are sure just say there isn't a way to do natively ( that would be a good answer )
the perfect answer would be a working code, but i am not lazy i am already implementing the code my self
There's no native control for this. It's probably a Button or maybe ToggleButton. You could create a background xml with different states for selected true or false. And when you click the button toggle the selected state.
Top might be a custom tab layout, or just a bunch of buttons with custom styling.
Main part looks like a listview with complex row views.
Bottom almost definately is a bunch of buttons.
You can implement it using ClickableListAdapter.There is also tab implementation.try it.
Just make it using image buttons and put filters in your ListView, or create your own filter form scratch !

Small Popup for Instructions, like foursquare ones

After seeing the last screenshots of new foursquare application and their balloon like cartoon instructions, I'd like to create some of these in my application.
I found a similar question for iPhone
Small popup for instructions... How?
Here is another screenshot of foursquare app:
I'd like to know how I could achieve that with Android.
Thanks in advance for any help.
UPDATE: This is what I could get so far but adding some buttons with a custom drawn background and layering them with a FrameLayout:
But I still couldn't get the triangle effect. Maybe there is something I can do with my custom background shape?
UPDATE2
After checking your suggestions, I decided to go with Aaron C idea and added an image with an arrow on it. This is my current result:
Thank you Snailer, QuickAction API project seems very much promissing. I'll check it out when implementing more features in my app.
Now, I just need to get the right color or maybe I could just let it this way. It seems nice too.
And, so, to summarize what I did:
Got my initial xml layout inside a FrameView.
As I'm using a frameview, everything I put in here will be piled one over the other. That's how I could add things to the layout.
In that framelayout, I put 2 relativelayouts whith an image with the triangle and a button to create the two upper popups. In the bottom I put a button only.
That's it. I hope it helps somebody.
Thank you very much again for all your help!
That sounds like a neat thing to implement. There might be a built-in Android variation on AlertDialog that achieves this, but if not here is how I would go about implementing it:
Create a new Activity whose background is black with a very high (low?) alpha color value. This will allow you to see through it to the previous Activity in the stack. Then, add your alert at whatever coordinates you like using a relative layout with padding values.
You might also want to add a touch listener that exits the Activity if the user touches the balloon (or maybe anywhere in the screen).
If you want to be fancy with coordinate placement of the balloon, you can pass this information into the new Activity using the Activity's launch Intent with the putExtra() methods.
It's probably achieved through skinning a toast.
The developer documentation shows a skinned toast in "Creating a custom toast view" at http://developer.android.com/guide/topics/ui/notifiers/toasts.html
You may want to look at the QuickAction API. It acheives this by using PopupWindow, skinned, positioned, and animated.

android custom button

I need to create some custom buttons as shown in the image below
what is the best approach to follow?
thanks
Abdul Khaliq
That's a hard one. I made a lot of custom views, and the first thing I would thinking of is, made one Button with that above image, and handle onTouch by yourself so you can distinguish which area the user hit. There you can also change the state of the button, like changing the image to a bevel one e.g. when the left button is hit.
Can you imagine this ansatz?
You can place two transparent "invisible" buttons over the top of a background in a LinearView. Like two ImageButtons with a transparent png inside.
It is also possible to make this background animated when buttons are clicked using android animation class.

Categories

Resources