Hello I have some questions for adding images for a ImageButton.
I have an icon for example a play button now if I hover over the button it just should get a blue surounding box the inside Image should not change.
Should I draw for every icon the two states or are there other options.
If an button is not clickable it should get Grey. Same how to do this? Add an additional Image to every Icon?
For what is the Checked drawable in the ImageButton?
ImageButtons have a drawable for their background (up, down, over, etc.) and a drawable for the image on top of the button (imageUp, imageDown, imageOver, etc.). The only ones you must provide are up for the background and imageUp for the icon. These are the defaults used when you leave the other states null. But for visual reasons, you need down for the background or it will be hard to tell if the button is being pressed. It's up to you whether you think you need to also change the icon appearance with an imageDown.
All you need is to add the background drawable for disabled. If you want the icon to also turn gray, you need to create a gray version of the icon and assign it to imageDisabled.
The Buttons in Scene2d all support toggle functionality. When you press it, it will toggle to the checked state, so you can use the checked drawable to change its appearance while it is stuck down. If you don't want that to happen, leave the checked drawable null.
Related
I am using the button as the side tab menus for item like 'Home','Games',etc. I can't figure out how to get such rectangle shape selection when button is pressed.
Can I use drawable res for the same. Please help.
You should use a custom drawable with left margin rectangle drawable 1dp to 5dp width. I think you already have the logic for toggling the current tab's button to only have this drawable.
I have an icon in my application and I made it clickable (When I click the icon, some action is called), but the problem is, you have to be really accurate. On the other hand the menu icon (the 3 dots) has a bigger "range" and when you click little bit outside, it is still working. Is there any way to achieve the same thing at the app icon? Or is there any better way to make a clickable icon in the upper left corner than using app icon?
Add padding to the icon, the more padding you add to it, the more clickable area you ll get!
Try to put a transparent button over your icon. Don't forget to make it unclickable and put enabled to false, so it doesn't intercepts the click intended for the icon.
I have been having a tuff few days with the EditTextPreference object. No matter which emulator I use this on, it seems to change color slightly but always makes my text the same color as the widget itself. (Yes, I know it's not really a widget).
I can change the TEXT color and the BACKGROUND TEXT color in the XML code, but this does not help because the "CANCEL" and "OK" confirmation buttons (which are part of the widget)to tap are yellow and impossible to see on the white widget background.
Is there any way in XML to make this widget a different color? This has been very frustrating.
You can set background colour of any widget by property
android:background="#ffff00"
enter any hex code at place of #ffff00
You can pick up hex code from here
you can also set a picture as a background of widget
android:background="#drawable/your_image"
place your_image in drawable folder
Is there a way to do both
button.setBackground(Color.green.darker());
and
button.setIcon(new ImageIcon(buttonImg.getScaledInstance(15, 15, Image.SCALE_SMOOTH)));
so that both the image and the background color are visible? Is there some sort of transparency setting on the button's image that I'm missing? Any help would be greatly appreciated.
EDIT:
Here is the image I'm trying to use. As you can see, it has transparency.
http://www.clipartlord.com/wp-content/uploads/2013/09/bomb3.png
What I am trying to get is the image to show up on the Button with the background color of green filling in the transparency. Right now when I try to do it, if I add the image at all, the background color is not visible whatsoever. But if I don't add the image, the background color is visible. I hope this helps.
Probably the LookAndFeel does not support what you want to achieve. Here is an image from the meta theme, on the left, and osx aqua theme.
If you want all of your JButton backgrounds to change you can try using a LookAndFeel that supports changing the UI. Unfortunately the aqua them does not let you change the default background for a button even using the UIManager#set
If you only want to do one button, you can change the button UI.
button.setUI(new BasicButtonUI());
That one doesn't look too nice, you can set the UI to one from another LookAndFeel,
button.setUI(new MotifButtonUI());
(Also doesn't look very nice, but now it buttons.)
Finally you can also create your own ButtonUI, or do some custom painting.
I have a simple soundboard which uses Buttons to represent the sounds. When a sound button is clicked. The background image is changed using the view.
Button butt = (Button)view;
butt.setBackgroundResource(buttons_on[media]);
buttons_on is a int[] representing the drawables of the buttons.
This all works perfect, but I also use a FragmentActivity to create a paged App. The App has 4 different pages which you can swipe through. When I change a button using the above code and swipe two pages to the right and than swipe back. The image of the button has changed back to it's default defined in the page.xml.
How can I prevent this behavior?
change the Buttons to ImageButtons and setting the src?
somehow prevent the page from reloading
Instead of doing that you should look at how to use a StateListDrawable. It will simplify your approach.