Reputation: 1500
I'm trying to customize the settings menu or create something with that functionality. I currently have a Toolbar with the title and a Settings button (with custom icon). This button opens a PopupMenu this way:
btnOpenMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PopupMenu popupMenu = new PopupMenu(HomeActivity.this, view){
@Override
public void setOnMenuItemClickListener(@Nullable OnMenuItemClickListener listener) {
super.setOnMenuItemClickListener(listener);
}
};
popupMenu.inflate(R.menu.menu);
popupMenu.show();
}
});
The popup menu is working but I need now to customize the view, at least to make it full width and center the text, as shown in the image:
Is it possible to do this with a popup menu? how can I extend the width of the menu and make it full width?
Thanks in advance.
Upvotes: 2
Views: 1584
Reputation: 2076
You can use ListPopUpWindow
for this. The advantage is you can customize the layout inside it to put list of strings with images also and etc. Try using this code.
ListPopupWindow listPopupWindow;
setUpListpopupWindow();
btnOpenMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listPopupWindow.show();
}
});
Set your list popup window here.
public void setUpListpopupWindow() {
listPopupWindow = new ListPopupWindow(BluetoothActivity.this);
listPopupWindow.setAnchorView(btnOpenMenu);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
listPopupWindow.setWidth(metrics.widthPixels); //sets width as per the screen.
listPopupWindow.setHeight(ListPopupWindow.WRAP_CONTENT);
listPopupWindow.setModal(true);
View filterLayout = getLayoutInflater().inflate(R.layout.your_awesome_custom_layout, null);
listPopupWindow.setPromptView(filterLayout);
}
Upvotes: 2
Reputation: 1442
Instead using pop menu for making it full width and center the text. Which I dont think is really easy.
Why dont you use Bottom Sheets.
There are lots of open source libraries available.Make use of it.
Upvotes: 1