显示一个弹窗,在其的右上角
主界面的布局
在你需要控件弹出菜单的,控件上面写点击事件,并且在点击时写
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.img_getmain_right:
registerForContextMenu(imgGetmainRight);
PopupMenu popupMenu=new PopupMenu(GetMainActivity.this,v);
popupMenu.getMenuInflater().inflate(R.menu.menu_getmain,popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
return false;
}
});
popupMenu.show();
break;
}
}
菜单的布局。Xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menu_getmain"
android:title="加入收藏"
android:icon="@mipmap/ic_launcher"
app:showAsAction="never"/>
</menu>
网友评论