我使用以下代码创建菜单,当我点击按钮时,它会显示弹出动画,如何禁用它?
setContentView(R.layout.activity_test_create_menu_in_code);
View b = findViewById(R.id.b);
final PopupMenu m = new PopupMenu(this, b);
m.getMenu().add(0, 1, 0, "Create");
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
m.show();
}
});
答案 0 :(得分:0)
弹出动画可以改变你的风格:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:popupAnimationStyle">@null</item>
</style>
答案 1 :(得分:0)
<style name="NoPopupAnimation" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupAnimationStyle">@null</item>
</style>
和
Context wrapper = new ContextThemeWrapper(this, R.style.NoPopupAnimation);
PopupMenu popup = new PopupMenu(wrapper, view, Gravity.END);
使用这种方式,您不需要更改整个活动的样式。例如,在我的例子中,Popup动画在华为设备上存在问题。所以我只需要为华为禁用动画。我就是这样做的:
Context wrapper = this;
if ("huawei".equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
wrapper = new ContextThemeWrapper(context, R.style.NoPopupAnimation);
}
PopupMenu popup = new PopupMenu(wrapper, view, Gravity.END);