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);
Related
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
I know how to set a button borderless in xml.But how to set button borderless in source code, because it is created dynamically.
Make button image and do:
button.setBackgroundResource(R.drawable.button_image);
button.setBackgroundResource(android.R.color.transparent);
don't forget to put exactly:
android.R.color.transparent
if you put R.color.transparent only (without android), there will be an error in the code when doing this
I need to create a custom button control that will inherit from the same Android style as all other buttons in my application. However, I want to be able to add several lines of text where some characters of the text will be in different colors. Is there anyway to achieve this, I can't seem to see a way?
Currently I have created a view that looks like a button by drawing the background, this is ok but I want the background etc to change with the application style.
You should make your button descend from the generic theme for Widget.Button. This way you can ensure that all the default settings will come through for you.
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 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/