I don't know how exactly this type of buttons is called that's why I can't even google about it.
You use that button to unlock phone - tap on it and move from left to right.
I'd like to add same button in my app. How to do it?
You should use SeekBar to achieve what you want. http://developer.android.com/reference/android/widget/SeekBar.html
Here is a good example
http://www.techrepublic.com/blog/app-builder/androids-seekbar-your-way/943
Try this for a library
https://github.com/sitepoint-editors/SwipeButtonExample
and this for a DIY
https://rightclicksolutions.wordpress.com/2014/04/09/android-slide-to-unlock-like-ios-mb-slider-slider/
You can overide onTouch() and change the location of the button acording to the x position. and when you lift the finger you can overide onUp() (im not sure thats the name of the method) and create an animation that will lead the button back to its place.
From your question I get that you might think its a button you can simply add from a list of buttons, well, its not. you need to manualy create it.
Related
When I try to drag my finger from one button to other, the first is released, the second is not pressed.
Practically I need the second to be pressed. I thought maybe there was some specific Listener to do this, but I could not find it.
Also, I would need to perform certain operations at the exact time that the button is released (banally, the color of the button can be stored in a local variable or in a text view as shown in the sample figure).
Sample Image
Thanks for the suggestions!
Have a look at the OnTouchEvent-Method. You could override it and listen for Motion Events like ACTION_HOVER_ENTER and ACTION_HOVER_EXIT.
In my application, I want to provide the functionality similar to Next, Previous and Done button at the top of keyboard. It is somewhat similar to this
Please let me know how can I achieve this.
I do not want to exactly implement the next,previous and done options. But using this three button click, I want to make three separate web service calls and fetch the results. Like, Active,Inactive and All kind of filters.
The standard Android way would be to provide an input method action with imeOptions. With the standard keyboard this will change the bottom right virtual keyboard button to the specified action. There's little point in trying to mimic iOS input behavior with the buttons above.
Do you want to just put the layout above the keyboard,so as to stop next,previous,etc button when keyboard is displayed.
If so,you can try adding below code inside your activity in android manifest,
android:windowSoftInputMode="adjustResize"
If you are looking for something else,then please show your xml code of the same.
my question is not only about onTouch events but about every method I can use to recognise a touch on certain areas of the screen.
Right now, I have a "background" image, which I use as layout that contains 2 "buttons": Start and Options as you can see here:
Ok, what I want to know is which is the best way to identify when are the user touching each button. By the way, should be nice also some info about how to deal with the different screen sizes.
Lots of thanks.
PD: seems I didnt explain it well. they are not "Android buttons" theirselves. The background is a whole image, where you can find 2 "buttons", but they are a part of the image. Thats because I need to know how to do this
I think you're missing some fundamentals, so I recommend to take a tutorial track.
As a direct answer to your question , you can see this page from the tutorial.
Why do you want to set the touchListener on whole screen and find the buttons?..You can simply set the OnClickListener or onTouchListener on both the buttons itself..
I want to set a button to be invisible because there will be a picture in front of it to act like the button. Do you guys know how to set this up in the xml?
thanks in advance.
Maybe the best thing you can do is to use directly an ImageView instead of a Button, setting always a OnClickListener on it in order to catch click action. Maybe you can also add a proper selector in order to get a visual feedback on the pressed/unpressed state.
I'm new on game dev for Android.
I have a game where I need to click on moving Buttons or TextViews(not important).
I extended FrameLayout class and added some Buttons(through addView method). Then I tried to use TranslateAnimation, but it seems it doesn't updates coordinates for click event (i.e. when I click on the moving button on new position, the event is not handling, but when I click on the origin place(where it has started moving), the event catches even if the button left this place).
Question: How to create a moveable label(or button) that handles click events? Do I need to use tricks like hit testing? Or, may be I use completely wrong approach for games(e.g. I need to draw text instead of adding the views in layout)? I will be happy if you can suggest another solution.
This is limitation of the Animation in Android. They fixed that in Android 3.0. Read here for more information http://android-developers.blogspot.com/2011/02/animation-in-honeycomb.html
An excerpt:
"Finally, the previous animations changed the visual appearance of the target objects... but they didn't actually change the objects themselves. You may have run into this problem. Let's say you want to move a Button from one side of the screen to the other. You can use a TranslateAnimation to do so, and the button will happily glide along to the other side of the screen. And when the animation is done, it will gladly snap back into its original location. So you find the setFillAfter(true) method on Animation and try it again. This time the button stays in place at the location to which it was animated. And you can verify that by clicking on it - Hey! How come the button isn't clicking? The problem is that the animation changes where the button is drawn, but not where the button physically exists within the container. If you want to click on the button, you'll have to click the location that it used to live in. Or, as a more effective solution (and one just a tad more useful to your users), you'll have to write your code to actually change the location of the button in the layout when the animation finishes."