I created a menu for my activity with 3 item with
showAsAction="never"
so in the right corner of the toolbar I have the menu button and when I click on it the menu appear in the right corner of the screen.
But if I press the menu button on the smartphone, the same menu appear in the bottom left corner.
How can I always open the top menu?
答案 0 :(得分:0)
这取决于Android版本,所以总是top.you将不得不创建自己的自定义拨号
答案 1 :(得分:0)
private void showStatusPopup(final Activity context, Point p)
{
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.custom_pop_up, null);
ListView l = (ListView) layout.findViewById(R.id.list);
String s[] = null;
final UserBean user = Utill.getUserPreferance(mContext);
if (user.isUserLogin()) {
s = loginMenuOptions;
}
else {
s = unknownUserOptions;
}
ArrayAdapter arrayAdapter = new ArrayAdapter<String>(mContext, R.layout.simpletextview, R.id.tvName, s);
l.setAdapter(arrayAdapter);
// Creating the PopupWindow
final PopupWindow changeStatusPopUp = new PopupWindow(context);
changeStatusPopUp.setContentView(layout);
changeStatusPopUp.setWidth(330);
//changeStatusPopUp.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
changeStatusPopUp.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
changeStatusPopUp.setFocusable(true);
// Some offset to align the popup a bit to the left, and a bit down,
// relative to button's position.
int OFFSET_X = VIEW_POART_WIDTH - 290;
int OFFSET_Y = 0;
// Clear the default translucent background
changeStatusPopUp.setBackgroundDrawable(new BitmapDrawable());
// Displaying the popup at the specified location, + offsets.
changeStatusPopUp.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
l.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
changeStatusPopUp.dismiss();
}
}
});
}