带有工具提示箭头的 Android PopupWindow
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21031488/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android PopupWindow with Tooltip Arrow
提问by Lee
I've seen a lot of questions about removing the border of a PopupWindow by passing null or new Drawable() to setBackgroundDrawable(). I'm having the opposite problem. I want a border around my PopupWindow, preferably with a tooltip arrow pointing to my anchor. Currently, my PopupWindow has no border. I've tried adjusting the margins, the background in the xml, the width and height of the layout, listview, and listview rows to no avail. Can someone please help me get a border and an image on the top? I'm trying to stick with the android SDK with this.
我已经看到很多关于通过将 null 或 new Drawable() 传递给 setBackgroundDrawable() 来移除 PopupWindow 边框的问题。我遇到了相反的问题。我想要一个围绕我的 PopupWindow 的边框,最好有一个指向我的锚点的工具提示箭头。目前,我的 PopupWindow 没有边框。我试过调整边距、xml 中的背景、布局的宽度和高度、列表视图和列表视图行都无济于事。有人可以帮我在顶部设置边框和图像吗?我正在尝试坚持使用 android SDK。
popup_menu_list.xml
popup_menu_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.github.jeremiemartinez.refreshlistview.RefreshListView
android:id="@+id/popup_menu_list_listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/color_white" />
</LinearLayout>
Java
爪哇
private void displayPopupMenu() {
LayoutInflater layoutInflater = getLayoutInflater();
View popupView = layoutInflater.inflate(R.layout.popup_menu_list, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
RefreshListView myListView = (RefreshListView) popupView.findViewById(R.id.popup_menu_list_listview);
mAdapter = new myAdapter(this, getAdapterData());
myListView.setAdapter(mAdapter);
popupWindow.showAsDropDown(mMyAnchor);
}
I just grabbed these as examples, but I want something like this where the popup points to the anchor:
我只是把这些作为例子,但我想要这样的东西,弹出窗口指向锚点:
But I get something like this:
但我得到这样的东西:
回答by M D
There are many libraries and codes available into Market. Links are given below:
Market 中有许多可用的库和代码。链接如下:
This is the QuickAction UI pattern. Take a look at:
这是 QuickAction UI 模式。看一眼:
Another alternative would be "super-tooltips":
另一种选择是“超级工具提示”:
https://github.com/nhaarman/supertooltips
https://github.com/nhaarman/supertooltips
Here's a demo of it:
这是它的演示:
https://play.google.com/store/apps/details?id=com.haarman.supertooltips
https://play.google.com/store/apps/details?id=com.haarman.supertooltips
From that first link/example looks like below image. These are just demos, but you can customize as per your requirement.
从第一个链接/示例看起来像下图。这些只是演示,但您可以根据需要进行自定义。
回答by Douglas Nassif Roma Junior
If you are looking for a simple library, I created one based on PopupWindow.
如果您正在寻找一个简单的库,我创建了一个基于 PopupWindow 的库。
https://github.com/douglasjunior/android-simple-tooltip
https://github.com/douglasjunior/android-simple-tooltip
回答by Andoctorey
You can simply use PopupWindow with view with vector background:
您可以简单地将 PopupWindow 与带有矢量背景的视图一起使用:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="20dp"
android:viewportHeight="162"
android:viewportWidth="196">
<path
android:fillColor="@color/black"
android:pathData="M0 26.9917C0 12.0846 12.09433 0 26.99583 0L169.0042 0C183.9136 0 196 12.09104 196 26.9917L196 100.0083C196 114.9154 183.9057 127 169.0042 127L124 127L98.5 162L73 127L26.99583 127C12.08644 127 0 114.909 0 100.0083L0 26.9917" />
</vector>
回答by Jacolack
A more in depth answer can be found at https://github.com/florent37/ViewTooltipwhich allows you to control many things including the direction from your view. A discussion and some methods can be found here.
更深入的答案可以在https://github.com/florent37/ViewTooltip找到,它允许您控制许多事情,包括您的视图方向。可以在此处找到讨论和一些方法。
回答by Nidhin
You can create your own custom tooltip by using xml only. I wrote a demo https://github.com/nidhinek/android-tooltipbased on PopupWindow
您可以仅使用 xml 来创建自己的自定义工具提示。我写了一个基于PopupWindow的演示https://github.com/nidhinek/android-tooltip