how to stay the button pressed - android

I want to stay the button pressed when clicked on that button. Button's background is done using StateList

You should consider using a ToggleButton for this kind of behaviour: http://developer.android.com/reference/android/widget/ToggleButton.html

Maybe have a look at/extend the CheckBox source code and use that as a starting point?

Related

Android Button Click not go through, but action still take place

I want when a button is pressed in my activity, for the click not to occur (such as clickEnabled being false) but I want the action that would have occurred to still happen.
For example, say I have a Dialer application:
When button "One" is pressed, the user will not see that the button was actually clicked, but the action of adding a 1 to the edittext will still occur. Thank you for your help!
I think you can make a selector as your button's background.and most important is samecolor no matter that is click , touch or idle . So through this ,you fake a no click effect.
And same time ,you can also add a click listener to this button to get the click event.
Hope that give you some suggestion.
I think you should simply use onTouchListener event for buttons instead of onclickListener

Setting onclick button color while waiting

I have an onclick listener for a button. Is there any way when I click the button, make the text change color until my new activity is brought up?
You can use setTextColor() on a button, too, as it extends a TextView (you can Ctrl+F on that page for "setTextColor()" to find the reference, it's under "Inherited XML Attributes"). So when the button is pressed you would use button.setTextColor(newColorInt); and when the loading is done button.setTextColor(oldColorInt);

how would you disable a button till the user navigates through prior buttons?

how would you disable a button until a user click on the buttons prior to it. One of the buttons has there bio info which is set in preferences. So I can't have them continue until they read the directions and fill there bio.
Disable it in the layout file and only activate it in the activity (onCreate()/onResume()) when the needed info is filled in
In onClick() for the button you want to press first call setClickable(boolean) for the button you would like to activate.
Also, if you want the button to start as being unclickable you should set the clickable attribute in your xml to false as well
<Button
android:clickable="false"
Hope this answers your question!
Perhaps make a state button for this task? Or have a state object that controls the button

How to dynamically change a pressed button background color?

I'm developing a question game and I want to change the answer button pressed background color to green if the answer is correct or to red if the answer is wrong just in the moment the user press the button.
Actually I have a custom_button.xml which I assign to the buttons in the layout:
<Button
android:id="#+id/la"
android:width="63dp"
android:height="65dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/la"
android:tag="#string/la"
android:layout_toRightOf="#+id/fa"
**android:background="#drawable/custom_button"**
android:layout_margin="3dp"
/>
Is there a way to change the pressed background of a button just in the moment the user is pressing the button?
I tried using setBackgroundDrawable() inside the button OnClickListener but this change the button behaviour for the next time the user click the button, not the actual.
bt.setBackgroundDrawable(getResources().getDrawable(R.drawable.custom_button_fail));
thanks in advance!
I tried using setBackgroundDrawable() inside the button OnClickListener but this change the button behaviour for the next time the user click the button, not the actual.
That's because the onClick method is called after the button is pressed. Your best choice here is:
Create two different drawables for your buttons. 1st for a normal button with normal background when it's not pressed and green background when pressed. 2nd for a normal button with normal background when it's not pressed and red background when pressed.
On onCreate assign the correct background to the buttons depending on whether the answer would be correct or not.
By the way, there is a shorter way to do so:
bt.setBackgroundResource(R.drawable.custom_button);

Android: How to do create custom EditText with a clickable arrow on the right

I would like to have an EditText with one modification: on the right but still inside the EditText there should an arrow pointing downwards that I can set OnClickListener to so that when the user clicks on the arrow it displays a menu.
What is the best way to do this?
Do you mean something like this ?
see image
Add the arrow by setting the drawable right attribute
android:drawableRight="#drawable/right"
to your EditText. Then you would need to set an OnTouchListener to get the events.
I did this by putting EditText and a Button into RelativeLayout, the Button (which has custom background drawable) is overlapping the EditBox.
When user clicks on it, the EditBox doesn't receive the click event.
Sounds like a combo box. If you look at the "Building Custom Components" section of the Dev Guide, they mention combo box briefly, but give details on how to build any custom component.

Categories

Resources