Android: How to change the default shape of a button? - android

Is it possible to change the default shape (i.e rectangular) of the button (normal button as well as imagebutton) to something else maybe like star or a triangle in Android? Any tutorials or sample code would be much appreciated.

That depends on how you define "shape".
Visually, you change the shape by changing the button background resource. See this previous SO question and answer.
However, I haven't tried this with something non-rectangular, so it is possible that while it will look like a star, the "hot zone" for clicks might still be the original rectangle.
You might look at the implementation of RatingBar in the Android open source code, which uses stars, and see if they do anything unusual.

Related

Android, Simple box inside a button?

I want to have a button like the one in the link below. How can i achieve it just by java code or xml? By the way it's going to be of a different color when pressed. I've explored similar posts but none helped. Any help appreciated.
The button which i want
Just make a View with large rectangle and add what you want(e.g. Label contains 'Number Of Students' and/or something else) in the view.
Then, add onClickListener to the View.
To change clicked colour, refer to here

¿Is it possible to put an icon with an action inside of EditText?

I'm looking forward to create an EditText with an Icon on the right that has some kind of functionality.
I've seen that the Google IO 2013 app has something like that on the search widget.
I want to know if its possible to do that with a simple EditText.
I've tried with a simple ImageView on the right of the EditText, but it looks really bad.
I would really appreciate if someone could point me in the right direction.
Thanks.
EDIT 1
This is an example of what I want. It looks really good. I have used the drawableRight and it doesn't look this good.
http://img836.imageshack.us/img836/1521/6faa.png
EDIT 2
I managed to build something that looks really similar to the SearchWidget with the voice recognition option.
I put two EditText next to each other (with a RelativeLayout), and set the margin left for the one on the right to -10dp. This way it looks like one EditText. I know this is not proper, but right now does what I want.
My problem now is the image, I'm using a 32x32 px image, because it fits fine, but it has really low quality, I'll look into that.
http://img560.imageshack.us/img560/9394/ilwp.png
You can definitely use a custom EditText with drawableRight as follows:
android:drawableRight="#drawable/your_drawable"
Refer
1.Custom EditText- 1
2.Custom EditText- 2

Fill with Color on Android

I have an image which include 10 boxes on my image view. When I click the one of boxes I want to change color of box (fill with color). How do I do that? Should I use Surface View or something else?
Update:
I found a solution. But if I use AsyncTask the code does not work. If I use a normal class the code works. I do not know why but I think problem is related with invalidate().

How to make the button which has a kinda image( I need a detail )

I would like to know how to make the button which contains a kinda icon.
I made up a LinearLayout first and the button belongs in it.
I tried the the icon to be in the Button by using 'android:drawableLeft="#drawable/*"
The icon was placed to too Left for me.
The button is a little bit long and text and icon are small so there are some space empty.
I mean, I want the icon to be more closer to the text than it was.
Now, icon is placed to the left and text is in center.
I want them to be together with a little padding.
I tried to use 'android:drawablePadding=7dip' but it didnt work.
I so want somebody to let me know how to do it.
Have a good day.
Thank you
You can use Custom Buttons are resizes button stretch image size and below link for custom Button Tutorial link
http://www.thesecretpie.com/2010/07/creating-custom-fancy-buttons-in.html
Thanks..!
There are two techniques. I suggest you look into:
Image Buttons
Image Views
With Image view you can create a button by using an onclick listener which can be created from within your activity or from your xml layout file.

Button containing images and text

I have to create a small panel like thing with a border.
This should contain a text, an image that describes the text and a button.
On clicking that button I have to do some operations also.
Which widget is suitable for this?
Can anyone suggests any idea?
ImageButton is what I can think of. Try the ApiDemo sample application comes up with android sdk too. Another tool you might need is DroidDraw (Free android UI designer) and hierarchyviewer.bat(inside android sdk tools) can also help you if you want to know how the other developers use for such purpose.
I have assumed that you want to display button with images + Text,
You can do it with Button. There are 2 ways to do it(Button with Image and Text).
By xml, you can set
android:background attribute of
button and the text which you set,
will be appeared above the
background.
By code, You can use
setBackgroundDrawable() , it is
used to set the background of a
button.
and If you want to display panel(By clicking on the handle of that panel, it will comes up with the many items as home screen) , slidingDrawer widgets is the best solution.

Categories

Resources