8

Can I set some message to appear like a "tooltip" for a TextView or Button?

Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
Adham
  • 63,550
  • 98
  • 229
  • 344
  • Tooltips usually work by appearing on mouseover (hover). How would a tooltip work on a touchscreen device, where there is no persistent mouse pointer? See also CommonsWare's comment [here](http://stackoverflow.com/questions/3350020). – Matt Ball Dec 13 '10 at 20:53
  • NOT exactly a tooltip , to be more clear ... when i set tje cursor inside a EditText view i need a message to appear ! – Adham Dec 13 '10 at 20:56
  • Okay. What kind of a message are we talking about here? A mockup image would help explain what you're after. – Matt Ball Dec 13 '10 at 20:58

2 Answers2

15

There's no concept of "hovering" in a touch screen, but you could set a LongClickListener for your View, and have a Toast appear after a long press. Something like this:

Toast viewToast = Toast.makeText(this, "My View Tooltip", Toast.LENGTH_SHORT);

View myView = (View)findViewById(R.id.my_view);

myView.setOnLongClickListener(new OnLongClickListener() {
    @Override
    public void onLongClick(View v) {
        viewToast.show();
    }
});

EDIT: After reading your comment, you should just use the hint attribute in your EditText XML layout:

<EditText
    android:hint="My tip here" />
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
2

-First set a textview with your hint and set it to invisible.

-Create an animation xml with alpha animation,specify how long you would like to display(at the end set the animation to zero alpha so that it remains invisible) and put it in res->anim folder

-Inside your onCreate and onClick methods of view that need tooltip

  1. set the text view to visible
  2. Hook the animation(like R.anim.tooltip) to this text view

-Use boolean flags and allow the user to switch off the tool tips in menu.

I'll leave the code specifics to you. You find them easily in stackoverflow.

Madhu
  • 253
  • 1
  • 8
  • 21