-2

Im writing an app with voice activated buttons. I would like the buttons on screen, when long-pressed to pop a toast next to the button giving the voice command the app will recognize (kind of like a tooltip). The toast should appear next to the button and last only as long as the button is held.

Questions:

*How to set Toast length to custom (long-click duration) time

*How to change position of toast to be closer to button clicked

AnthonyW
  • 1,910
  • 5
  • 25
  • 46

2 Answers2

1

I don't actually see a question here, but you'll need to use your own view for this, not an actual android.widget.Toast.

kabuko
  • 36,028
  • 10
  • 80
  • 93
0

I think what you are looking for is http://developer.android.com/reference/android/view/View.OnLongClickListener.html

Set an OnLongClickListener to launch a Toast.

http://developer.android.com/reference/android/widget/Toast.html

Edit

For setting the length of the toast only the values of LENGTH_SHORT and LENGTH_LONG may be use. This is because these are flags specified for that class. The only solution to create a longer toast would probably be to launch the toast multiple times.

For setting the position of the Toast you can set the Gravity of the toast and specify an offset. You could set the position to Top Left and use the view's position to compute the offset for your tooltip.

Bill
  • 413
  • 2
  • 10
  • That's along the lines of what I was thinking. I re-edited to main post to highlight the real questions I had. – AnthonyW Mar 22 '12 at 20:22
  • AnthonyW You cannot use values other than LONG and SHORT to set the time. They are flags not durations unfortunately. Some people (http://stackoverflow.com/questions/2220560/can-an-android-toast-be-longer-than-toast-length-long) have suggested you just run the Toast multiple times. Also the position I believe must be controlled through the gravity and an X, Y offset. See Toast.setGravity. You could put the gravity to be top left and use the views position to calculate the offset – Bill Mar 22 '12 at 20:55
  • Looks like multiple SHORT Toasts and gravity + offset is the way to go then. Thanks a million Bill! If you could edit your comment into your answer I can check this question off. – AnthonyW Mar 22 '12 at 21:22