问题描述
当我使用BottomAppBar菜单更改它时,我的菜单出现问题
bottomAppBar.setFabAlignmentModeAndReplaceMenu(BottomAppBar.FAB_ALIGNMENT_MODE_END,R.menu.detail_page_menu);
是com.google.android.material:material:1.3.0-alpha02
中可用的功能。
我有2个菜单R.menu.menu_main
和R.menu.detail_page_menu
,我在BottomAppBar中使用这些菜单,它们在片段发生变化时进行更改。
两个菜单都包含2个元素。
这是菜单应显示的正确方式(并且仅在第一次或第二次出现,有点随机):
这是第一次或第二次打开该片段和菜单开关之后发生的情况:
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity.MainActivity">
<FrameLayout
android:id="@+id/fragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="UnkNownIdInLayout"
android:layout_marginBottom="38dp"
/>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:layout_alignParentBottom="true"
android:id="@+id/coord"
>
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:fabAlignmentMode="center"
app:fabAnimationMode="scale"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:backgroundTint="@color/colorAccent"
android:theme="@style/Theme.MaterialComponents"
app:hideOnScroll="true"
app:layout_scrollFlags="scroll|enteralways"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:maxImageSize="36dp"
android:src="@drawable/money"
app:backgroundTint="@color/colorPrimary"
app:layout_anchor="@id/bar" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/snackbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rotation='180'
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
这是当我在MainActivity.java中更改菜单时
public void setFabSecondPosition(){
// Hide navigation drawer icon
// Move FAB from the center of BottomAppBar to the end of it
bottomAppBar.setFabAlignmentModeAndReplaceMenu(BottomAppBar.FAB_ALIGNMENT_MODE_END,R.menu.detail_page_menu);
// Replace the action menu
// Change FAB icon
fab.setimageDrawable(fabIconSecond);
}
public void setFabMainPosition(){
bottomAppBar.setFabAlignmentModeAndReplaceMenu(BottomAppBar.FAB_ALIGNMENT_MODE_CENTER,R.menu.menu_main);
fab.setimageDrawable(fabIconFirst);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)