带有Tooltip Arrow的Android PopupWindow

时间:2014-01-09 21:25:27

标签: android popupwindow

我已经看到很多关于通过将null或新的Drawable()传递给setBackgroundDrawable()来删除PopupWindow边框的问题。我遇到了相反的问题。我想在我的PopupWindow周围有一个边框,最好带有指向我的锚点的工具提示箭头。目前,我的PopupWindow没有边框。我已经尝试调整边距,xml中的背景,布局的宽度和高度,listview和listview行无济于事。有人可以请帮助我在顶部获得边框和图像吗?我试图坚持使用Android SDK。

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>

爪哇

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);      
    }

我只是抓住这些作为例子,但我想要这样的东西,弹出指向锚点:

enter image description here

但我得到这样的东西:

enter image description here

7 个答案:

答案 0 :(得分:56)

市场上有许多图书馆和代码。链接如下:

这是QuickAction UI模式。看看:

  1. QuickAction-Dialog

  2. Quick-action-pattern-in-Android

  3. Chrome Style Help Popups

  4. 另一种选择是&#34;超级工具提示&#34;:

    https://github.com/nhaarman/supertooltips

    以下是它的演示:

    https://play.google.com/store/apps/details?id=com.haarman.supertooltips

    从第一个链接/示例看起来如下图所示。 这些只是演示,但您可以根据您的要求进行自定义。

    enter image description here

答案 1 :(得分:11)

如果您正在寻找一个简单的库,我创建了一个基于PopupWindow的库。

https://github.com/douglasjunior/android-simple-tooltip

Demo

答案 2 :(得分:2)

https://github.com/skydoves/Balloon

这个库提供了一个轻量级的弹出式工具提示,完全可定制的箭头和动画。 100% Kotlin 包含所有必要的文档。它也受到积极管理。

这是他们页面上的一些 gif;

e

另一个,

e

答案 3 :(得分:1)

您只需将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>

答案 4 :(得分:1)

https://github.com/florent37/ViewTooltip上可以找到更深入的答案,该答案使您可以控制许多事情,包括从视图中查看方向。可以在here中找到讨论和一些方法。

编辑: 这是一个示例gif: enter image description here

答案 5 :(得分:1)

对于 Android 8.0(API级别26)或更高版本 ,您可以使用:

<android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:tooltipText="Send an email" />

在您的代码中:

// Kotlin
val fab: FloatingActionButton = findViewById(R.id.fab)
fab.tooltipText = "Some tooltip"
// Java
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setTooltipText("Some tooltip");

答案 6 :(得分:0)

您只能使用xml创建自己的自定义工具提示。我基于PopupWindow编写了一个演示https://github.com/nidhinek/android-tooltip