I'm trying to put a bottomAppBar
to mainActivity
.
So I tried and check lots of stuff in here but couldn't find any solutions.
MainActivity's XML code is below(It has another constraint layout as a parent but didn't add here.)
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppbar"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_gravity="bottom"
android:backgroundTint="@color/colorGray"
app:fabAlignmentMode="center" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/bottomAppbar"
app:fabCradleRoundedCornerRadius="-10dp"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
So after that, I prepared a bottomappbar_menu.xml
in menu
directory and I tried to attach this menu to my MainActivity
file's OnCreate
method like below:
bottomAppbar.replaceMenu(R.menu.bottomappbar_menu)
Also styles.xmsl
is like below,
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
But when I install to phone, it's seen like below. I don't see any menu item:
It seems a problem I had.
Are you using
setSupportActionBar(bottomAppBar);
together with replaceMenu
?
In that case, remove setSupportActionBar
and everything should work.