Note : This is popup menu not popup window.So I request you all to read carefully.
I have implemented pop menu. It is displaying in half of the screen. I want to spread this to entire width of device. I tried to change its style by setting layout_width
as match_parent
but with no success.
Below is what I tried so far:
Style
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="popupMenuStyle">@style/PopupMenu</item>
</style>
<!-- Change Overflow Menu Background -->
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#888888</item>
<item name="android:layout_width">match_parent</item>
</style>
Below is my java code:
PopupMenu menu = new PopupMenu(getActivity(), tvnext);
for (int i = 0; i < array.size(); i++) {
menu.getMenu().add(1, i, 1, array.get(i).getAccountName());
}
menu.show();
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setUpNextFunctionality(item.getItemId());
return false;
}
});
P.S : Please don't suggest me to use popup window. This is my last option if nothing work.
Head to your WordPress dashboard and go to Popup Maker » Add Popup, and you'll see the popup editing screen appear. On this screen, you'll want to enter a name for your popup. Plus, you can also enter an optional display title as we did in this example. Your visitors will be able to see this optional display title.
I got your question. Instead of modify something use new widget which can easily fulfill your necessary and compatible with newer version.
Google introduce new Material concept as Bottom-Sheet
To use it in android you can use git hub libraries like this.
I don't think you can do that without implementing of your own popup window similar to PopupMenu
. If you will check MenuPopupHelper::createPopup
:
@NonNull
private MenuPopup createPopup() {
final WindowManager windowManager = (WindowManager) mContext.getSystemService(
Context.WINDOW_SERVICE);
final Display display = windowManager.getDefaultDisplay();
final Point displaySize = new Point();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(displaySize);
} else if (Build.VERSION.SDK_INT >= 13) {
display.getSize(displaySize);
} else {
displaySize.set(display.getWidth(), display.getHeight());
}
final int smallestWidth = Math.min(displaySize.x, displaySize.y);
final int minSmallestWidthCascading = mContext.getResources().getDimensionPixelSize(
R.dimen.abc_cascading_menus_min_smallest_width);
final boolean enableCascadingSubmenus = smallestWidth >= minSmallestWidthCascading;
final MenuPopup popup;
if (enableCascadingSubmenus) {
popup = new CascadingMenuPopup(mContext, mAnchorView, mPopupStyleAttr,
mPopupStyleRes, mOverflowOnly);
} else {
popup = new StandardMenuPopup(mContext, mMenu, mAnchorView, mPopupStyleAttr,
mPopupStyleRes, mOverflowOnly);
}
// Assign immutable properties.
popup.addMenu(mMenu);
popup.setOnDismissListener(mInternalOnDismissListener);
// Assign mutable properties. These may be reassigned later.
popup.setAnchorView(mAnchorView);
popup.setCallback(mPresenterCallback);
popup.setForceShowIcon(mForceShowIcon);
popup.setGravity(mDropDownGravity);
return popup;
}
you will see that size of PopupMenu kind of hardcoded as per display size. So probably easy way is to check PopupMenu
related source code and implement something similar, but with sizes which you'd like to have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With