如何在下图中提供像facebook这样的弹出窗口?尝试与aleart对话

时间:2018-06-01 09:55:59

标签: android xml android-layout android-recyclerview alertdialog

我想弹出像这样的Facebook

enter image description here

Hello Guys, 上图是您可以看到弹出按钮的图像。我尝试使用AleartDialog实现这一点,但它在中心打开。我只想在那个按钮下面。

LayoutInflater inflater = (LayoutInflater) 
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.layout_show_options, null);
 new AlertDialog.Builder(this)
            .setView(view)
            .create().show();

任何帮助将不胜感激。谢谢

2 个答案:

答案 0 :(得分:0)

使用弹出菜单  点击按钮打开菜单 menu.xml文件

 public void showMenu(View v) {
        PopupMenu popup = new PopupMenu(this, v);
        popup.setOnMenuItemClickListener(this);
        popup.inflate(R.menu.actions);
        popup.show();
    }

@Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.archive:
            archive(item);
            return true;
        case R.id.delete:
            delete(item);
            return true;
        default:
            return false;
    }
}

Java代码:

{{1}}

答案 1 :(得分:0)

使用弹出菜单

    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/unfriend"
        android:icon="@drawable/ic_mail"
        android:title="Unfriend" />
    <item android:id="@+id/edit_friend_list"
        android:icon="@drawable/ic_upload"
        android:title="Edit FriendList"
        android:showAsAction="ifRoom" />

</menu>


public void showPopup(View v) {
PopupMenu popup = new PopupMenu(this, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.menu_example, popup.getMenu());
popup.show();

}

@Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.unfriend:
            // 
            return true;
        case R.id.edit_friend_list:

            return true;
        default:
            return false;
    }
}

希望它会有所帮助。

有关详细信息,请访问以下链接。

https://www.tutlane.com/tutorial/android/android-popup-menu-with-examples

https://www.javatpoint.com/android-popup-menu-example

http://www.coderzheaven.com/2013/04/07/create-simple-popup-menu-android/