如何在Android中显示ToolTip? [英] how to display ToolTip in android?
问题描述
当我在视图上移动光标时,我想显示ToolTip(QuickAction View).可以请给我一个简单的例子吗?工具提示将仅包含文本值.
I want to display the ToolTip(QuickAction View) when I am moving my cursor on the view. Can any one please give me the simple example for it? tooltip will only contains the text value.
推荐答案
Android仅支持从Android 4.0开始的ActionBar按钮使用工具提示".但是正如Jaguar已经提到的那样,Android中的工具提示没有太大意义,因为没有悬停的概念.
Android supports "tool-tip" only for ActionBar buttons from Android 4.0 on. But as Jaguar already mentioned, tool-tips in Android doesnt make so much sense, since there is no concept of hovering.
在Android 4.0中,如果长按按钮,则会显示普通标题文本(您在xml文件中设置或通过代码设置).但是,如果屏幕上有足够的空间,它将始终在ActionBar中的图标旁边可见.
From Android 4.0 the normal title text (that you set in the xml file or via code) will appear if you make a long click on the button. But if enough space is on the screen, it will be visible in the ActionBar all the time beside the icon.
如果您希望将其用于自定义视图,则需要自己添加一个 LongClickListener
转到您的视图,并显示 Toast
:
If you want to have it for a custom view, you need to implement it yourself by adding a LongClickListener
to your view, and show a Toast
when pressed long:
view.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
Toast.makeText(v.getContext(), "My tool-tip text", Toast.LENGTH_SHORT).show();
return true;
}
}
当然,您应该为字符串使用资源,而不是硬编码字符串.
Of course you should use a resource for the string, and not the hard coded string.
这篇关于如何在Android中显示ToolTip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!