如何在android中设置弹出菜单的边距?
我在屏幕右上角有一个弹出菜单。我想在它的右边留一些空白。怎么做?我找不到任何解决方案。每个地方都有弹出窗口。但是我想要有弹出菜单的。请提供帮助。带有正确代码的建议将非常有用 我想在弹出菜单的右边留出一些空白如何在android中设置弹出菜单的边距?,android,Android,我在屏幕右上角有一个弹出菜单。我想在它的右边留一些空白。怎么做?我找不到任何解决方案。每个地方都有弹出窗口。但是我想要有弹出菜单的。请提供帮助。带有正确代码的建议将非常有用 我想在弹出菜单的右边留出一些空白 您能提供所需屏幕的图像吗?@DroidAks我已经添加了所需屏幕。请检查。请解释您的解决方案!反射应该被视为一种黑客的解决方法,而不是一种解决方案。应该有一个合适的方法来实现这一点,特别是材料设计建议弹出窗口应该有边距。。。 try { Field fListPopup = menu
您能提供所需屏幕的图像吗?@DroidAks我已经添加了所需屏幕。请检查。请解释您的解决方案!反射应该被视为一种黑客的解决方法,而不是一种解决方案。应该有一个合适的方法来实现这一点,特别是材料设计建议弹出窗口应该有边距。。。
try {
Field fListPopup = menuHelper.getClass().getDeclaredField("mPopup");
fListPopup.setAccessible(true);
Object listPopup = fListPopup.get(menuHelper);
argTypes = new Class[] { int.class };
Class listPopupClass = listPopup.getClass();
// Get the width of the popup window
int width = (Integer) listPopupClass.getDeclaredMethod("getWidth").invoke(listPopup);
// Invoke setHorizontalOffset() with the negative width to move left by that distance
listPopupClass.getDeclaredMethod("setHorizontalOffset", argTypes).invoke(listPopup, -width);
// Invoke show() to update the window's position
listPopupClass.getDeclaredMethod("show").invoke(listPopup);
} catch (Exception e) {
// Again, an exception here indicates a programming error rather than an exceptional condition
// at runtime
Log.w(TAG, "Unable to force offset", e);
}