Setting onclick button color while waiting - android

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);

Related

Android Button performClick

In order to fudge multitouch buttons, I set a massive invisible imageView over top of everything. The I just poll for where it was touched and call performClick on the button in that area under it. Now my problem is that performClick only calls the onClick method, and doesn't actually perform a legitimate button press, so there's no animation (color change etc). I have a custom xml for the buttons, and it worked fine without the imageView. I try using setPressed and setEnabled, but the png never changes, and the button looks static. What am I missing?
How about tying a Boolean to each button. All the button logic does is flip flop the variable and maybe change an indicator (button color or text) to pushed/not pushed. Shouldn't be more than 3 or 4 lines of code executed per button press. Fire the heavy code when a 'do it' button is pressed. That would have to be faster than computing which button was pressed under the overlay...

how to stay the button pressed

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?

what is use of image button?

I'm new to Android application development.
I would like to ask the use of image button in Android programming when simple button can also add the image with the button. How can we generate click event of image button?
The Image Button control is a special type of button that displays a Drawable graphic instead of text.
The Image Button and Button controls are both derived from the View class, but
they are unrelated to each other. The Button class is actually a direct subclass
of Text View (think of it as a line of text with a background graphic that looks
like a button), whereas the Image Button class is a direct subclass of Image View.
If you will look in the API for Button you will see that it has a method called setOnClickListener that is inherited from View. Since ImageButton is also a view, you can also call the same method for it.
The only way that I see to use an image in a Button is by using android:background in the XML. This is only used for setting what's shown behind the text of a button. You should use ImageButton when you want to make a button that only uses the image as its defining feature. If you end up wanting to only see the image and have no part of the button background visible, you can set android:background on the button to use an invisible Drawable.

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