I have a group of buttons which enable user to select certain views on the touch screen.
I want to have the user know which view is active by showing a halo (or any other style) around the button. I mean when the button is clicked it's normal state is changed to different style but it is still normal.
I googled and checked in stackoverflow, that it is not possible to change the style at runtime.
How can I achieve the desired effect?
I have some silly ideas which I won't implement unless as last resort, like making two buttons at same positions and changing their visibility.
Or I can put each button in it's own linear layout and then set the background color of each of them, if it is possible.
Or some ImageButton manipulation maybe.
I have already overridden the default style for button for normal pressed states.
And setting focus(when in focusInTouchMode) causes problem, so that's a NO (already tried that).
Even if style can't be changed, please advise some tip to achieve the effect, it's not necessary to do it the style way. I just want o let the user know which view is selected through buttons.
use state list and set its focussed state drawable as the button with a ring around it and then at runtime say button.requestFocus(). see here for more on state list...
Go for selector xml background for each button. Best Resort
Check this link
How to set image button backgroundimage for different state?
Hpoe this helps
or you can use like ::
Button button;
public void onClick(View v)
{
button.button.setBackgroundColor(**color**);
button.setBackgroundResource(**res**)
}
Related
I want to use FloatingActionButton for "like" action, but there should be two states for this, liked and unliked. So ToggleButton is suitable for this, but is there anything that combines the feature of these two kinds of button?
You can use the checkbox with checked and unchecked images. so that you can able to manage it for like and like within same button action. this link will help you to get the checkbox selector which use icons for different state.
Basically this depend on your scenario,for eg if want to show like dislike only then use toggle button only and if want to perform some action then use floating action button with all the action..
Like for particular page change background black white,increase text size etc..All depends on scenario..And always try to choose best not to fail at any stage...For anything pls ask
Framework: Android
I have a TextView where I would like to change the text on keeping an ImageView pressed.
Note: I am not referring to changing the text on clicking the view, but on pressing the view and on the amount of time that it is pressed.
e.g. I press the image and the text becomes 2. Keep it pressed for another half a second and the text becomes 3.
I haven't found a similar question yet, yet if you have, please redirect me. Thank you.
Make use of OnTouchListener and run your number changing algorithm in ACTION_DOWN
I am working on a game project.
I have 4 buttons on my screen. User has to select one of the 4. If user selects the correct one, it works fine. but if user selects incorrect one, I want to highlight the correct answer even though user didnt clicked it.
I have presentation due tomorrow. Can anybody point me to some example source or explain it here, as to how can I accomplish it.
You can set the correct buttons background color or image while clicking other buttons
Whenever user clicks on the incorrect button simply call :
correctButton.setPressed(true)
This will highlight the correct button as per your requirement.
you can do one thing..
Call Button.requestFocus() method to get the focus.
Create a custom selector for you Button's background. there
< item android:state_focused="true" android:drawable="#color/your_color" />
Hi all I am trying to show an Android spinner, but not show it as grayed out. I tried using setFocusable(false), which works fine on edit boxes, but not on spinners. I don't want the spinner to changeable unless I tell it to be. Basically I have a screen displaying data that I want to put in "update mode". Until the user has chosen to update the data, it should be view only. Any ideas?
maybe you can create a custom selector and set it to the spinner background,
check out this link for the selectors
I ended up cheating a little. I got the background image before disabling the field, then set the background to that image after disabling the field.
// Deal with spinners. I don't want to gray out the background
// because it looks bad against our dark theme.
Drawable d = type.getBackground().getCurrent(); // the enabled background
type.setEnabled(enabled);
// set all of the spinners back to the enabled background
if(!enabled){
type.setBackgroundDrawable(d);
}
I did my homework and this question has been asked a few times, but never answered with a solution to the problem. The question is, how do you change the size of the checkbox button in a checkbox compound button?
In my case I have a checkbox with a custom button attribute pointing to a selector xml file containing items for each possible state pointing to png images. I want to be able to specify in dp the size that these images are displayed as the button for the checkbox.
The answer to this question is NOT to change the android:layout_width of the checkbox itself. Anyone know how to do this?
Also, things I've tried include adding widths and heights to the selector and items. I've tried adding my selector to a Button and resizing the button (which works for the button alone), but I can't figure out how to specify to the CheckBox that it should use that Button xml.
I just ran into this problem myself. My checkbox has no text, and in that case this works well:
set
android:background="#my_selector_drawable"
instead of the button attribute. To avoid the standard button on top of the image, set
android:button="#null"
Now you can set the size of the checkbox with the normal android:layout_width & android:layout_height.
If you want a checkbox with text as well, this wont work
Well for now the best I can do seems to be to build my own checkbox using a button by keeping a boolean for the state that gets inverted in the OnClickListener and calling setBackgroundResource to swap between the "checked" and "unchecked" drawables.
Meh. At least I can resize the button to be exactly what I want. Hopefully someone will come up with a better way to do it.