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
Related
I have some text in the strings, and when you swipe your screen, they will change. So I want to make a button visible only, if the 3. text is visible.
<item>for free</item>
<item>easy to use</item>
<item>lets start</item>
When the "let's start" appears on the screen, I want my button to appear also on the screen, but only, when this string is visible "lets start".
These strings are in a textview, and they coded to change for swipe.
How to make this?
I know we have to implent somehow setVisibillity. and maybe add a listener?
How about comparing current TextView text?
if(yourTextView.getText().toString().equals("let's start")){
yourButton.setVisibility(View.VISIBLE);
}
if i understood correctly that should work.
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" />
How do add description or hint. When i touch a Button / ImageButton, I need description or hint.
Thanks in advance.
I am not sure this approach is a good idea since when you touch a Button in Android, it get's in pressed state, and when you release it will trigger the button's action. I suggest you use a different approach such as a properly formated TextView under the Button or ImageButton.
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**)
}
I'm trying to make iPhone-style EditText element on android.
The one that will have an additional clear button appear on the right after text input.
Adding a new button is not a problem, but I'm a bit stuck with another thing.
A button occupies some space on the right part of EditText, and now characters display beneath the button. How to change maximum shown length of input for EditText?
I want EditText width to be N pixels, and editable area to be N-M pixels.
EditText.setWidth changes width for whole edit box.
EditText.setEllipsize should be the proper solution, but docs are empty, and as I see it truncates text based on some String value.
Applying a LengthFilter cut's the input length to number of characters.
Thanks in advance.
I suspect that android:drawableRight will save you a lot of pain.
Seems I've found a solution.
EditText.setPadding(l,t,r,b) seems to work fine, applying only for editable area
Try this : http://mytechead.wordpress.com/2012/02/07/create-ios-like-cleartextbutton-in-android/
This is a very old question, but thought I'd add my two cents for kicks. I'd probably use a 9 patch for this and set the content area to stop the text before it hits the button area.
This would require creating a custom view so that you can add a button in the desired position using relative layout so that it can be clicked to clear the edittext.
Alternatively you can use the compound drawables, but you would need to implement something like this
Handling click events on a drawable within an EditText so that you can handle the click events. Keep in mind that I doubt the button states (eg the down state) will work using this method.