我想弹出像这样的Facebook
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();
任何帮助将不胜感激。谢谢
答案 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/