how to create fancy button in android? - android

How to create a button as shown in the picture:
and also Image name Button should permanently change color on click. Moreover I will be creating this button dynamically from the android file. So it will be good if somebody suggest me in that way instead of xml files way.

Have a look at the ImageButton class. You can easily create this at runtime so long as you have the picture file for your button in your resources. For it to permanently change colour simply create the different coloured version of the file, put that in your resources folder too and run some code on the onClick of the button to change the image of the ImageButton to the different coloured image. Should take no more than a few lines of code.
See: https://developer.android.com/reference/android/widget/ImageButton.html

Related

Change the button style if clicked in android

I have created a lot of buttons, in the java code, which represent some houses(for example). I want to create another button which is called "selection multiple". When i click on this button(selection multiple), all the others buttons(the houses) will change style or color when I click on them.
The problems is that I create the buttons ( house ) in the java code so i don't find how to change their style when I click on them /:
Button macase = new Button (this);
macase.setText("o"+Numcase);
tr.addView(macase);
Once you have a reference to your button object, you can change it's image or background (for example) with these functions.
macase.setImageResource(R.drawable.myicon);
macase.setBackgroundResource(R.drawable.mycustomButton);
In the second case, mycustomButton is an XML file with the custom style you want to apply
as far as I understand your problem is setting the Color of the button programatically.
You could for example do it like this:
macase.setBackgroundColor(Color.BLUE);

edit imagebutton picture

I made an app that displays an AlertDialog once I click on an ImageButton in eclipse.
But when I was trying to input a picture onto the ImageButton, I only found a way to do it in the XML graphic layout of eclipse via right clicking on the Button and then on "edit src". Is there a way to put in the picture from written XML itself?
Yes. You can put a picture into the written xml of an Android layout file.
With your xml file open in eclipse, there are two tabs at the bottom of the layout:
Graphical Layout
.xml
Press the ".xml" tab and you can edit the raw xml.
In order to add an image to your ImageButton, do this:
android:background="#drawable/your_image"
There are also other tags that work too, such as android:src, and the differences are described here: What is the difference between src and background of ImageView.
There are also ways to add the image or change the image programmatically in your .java file. This is useful only if you want to change the image dynamically (although, see below for changes of state)
And, this is just the beginning of what you can do...
If you don't want the default frame around the button, you can use other items, such as an ImageView to make your button.
If you want to display various graphical images depending on state such as "pressed", "selected", etc, then you can specify a "selector" file instead of "your_image". There are many examples of how to make "selector" files on this site, and how to implement the other upgrades to your button.
Have fun!

android custom button with default selector

I have a listview in which i have an image and text content getting populated from the java code.
I'm unable to get the default orange selector working on the image. The image is placed ontop of button as setBackgroundResource() from Java.
Can anyone help me with the same?
you could do change background by using drawable property of button in xml file. if you will use this setbackgroundresource() then it will ruin the effect of clicking on it. if u still want to use image as background source then u should create selector xml file for the button background.

how do I change the style of a button in android?

I want to change the style of a button in an android app. here is a picture that has both kinds of buttons, the one that I have now, and the one that I want to switch to:
the kinds of buttons that I am using now, look like any of the letters on that keyboard. the ones that I want to use like like the arrows. I would I go about changing this. I prefer to do it in xml but I can do it in java if that is the only way. Thanks
change the background of the Button to a png image with arrows!
in XML use android:background="#drawable/yourimage"
To get more sophisticated control check here,
Standard Android Button with a different color

I Want to create custom Circular Button which will Focus on click how to do?

I am trying to create one custom button which is circular and when i click that button i want that button FOCUS and COLOR change and i don't know how to do exactly so any one can help me or show me that code how to do?
You can use a regular Button and specify custom Drawable for it and then apply it to the Background property of the button. See the ApiDemos for examples of styling controls.
You can use two (or more) drawables for one Button and change the drawables in various states (focus, press, etc). Look at this: http://blog.androgames.net/40/custom-button-style-and-theme/

Categories

Resources