带有提示箭头的Android PopupWindow

60

我看到很多关于通过传递null或new 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>

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

我只是拿这些作为示例,但我想要类似这样的东西,其中弹出窗口指向锚点:

enter image description here

但我得到了像这样的东西:

enter image description here


编辑了带有期望弹出窗口外观示例的内容 - Lee
8个回答

65

先生,您提供的链接显示在Eclipse中存在依赖关系。 - user1545654
这是链接,我不知道如何添加依赖。请参考:https://github.com/nhaarman/supertooltips - user1545654
先生,我是相对新手,您能给我一个链接来做这个吗? - user1545654
很遗憾这个不再被监控了。 - spy
是的,这个仓库已经“停止更新”了。是否有任何新的针对当前Android版本或官方Google库的东西? - androidguy
显示剩余2条评论

15

嗨 @Douglas Nassif Roma Junior,我已经检查了你的库,非常好。请问你能告诉我如何在对话框上使其工作吗?谢谢。 - Rahul Khurana
示例项目的当前版本包含了一个如何使用对话框的示例。请看这里 - Douglas Nassif Roma Junior
你好,对于API 26,它运行得很好,但是在API 26以下的版本中,在屏幕上显示的工具提示位置不正确。您能否提供可能的原因或解决方法? - Surendra Kumar
请查看 已知问题 - Douglas Nassif Roma Junior

4

对于Android 8.0 (API level 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");

4
您可以使用带有矢量背景的视图来简单地使用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>

3
可以请您发布相同的向量图像,但上箭头。 - Priyanka Madgundi

3

https://github.com/skydoves/Balloon

这个库提供了一个轻量级的弹出式工具提示,带有箭头和动画效果,可完全自定义。100% Kotlin编写,配备所有必要的文档。目前正在积极维护。
以下是他们网页上的一些gif;

e

另一个。

e


2

Gradle 无法编译它。 - ravid rinek
3
适用于底部位置,但不适用于顶部位置。 - Surendra Kumar

0

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接