I'm assembling an app with a Botton navigation bar in Android with Android Studio. With two icons it looked fine, but when I added four, the icons look cropped. I can't find any other error like this. Any suggestions are welcomed.
Cropped icons bottom nav 4 options
Here is the code for the Bottom Navigation (bottom_navigation.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_lines"
android:enabled="true"
android:icon="@drawable/ic_lines_off"
android:title="Lines"
android:background="@android:color/transparent"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_contacts"
android:enabled="true"
android:icon="@drawable/ic_contacts_off"
android:title="Contacts"
android:background="@android:color/transparent"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_conversations"
android:enabled="true"
android:icon="@drawable/ic_conversations_off"
android:title="Conversations"
android:background="@android:color/transparent"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_settings"
android:enabled="true"
android:icon="@drawable/ic_settings_off"
android:title="Settings"
android:background="@android:color/transparent"
app:showAsAction="ifRoom" />
</menu>
In my activity.xml I call the bottom menu like this:
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:itemIconTint="@drawable/bnv_tab_item_foreground"
app:itemTextColor="@drawable/bnv_tab_item_foreground"
app:menu="@menu/bottom_navigation" />
Question Update:
I tried changing
app:showAsAction="ifRoom"
for
app:showAsAction="always"
And it doesn't solve the problem. There is no change to the issue. And it does not show the tag in every icon as it should. Only on the selected one.
One way of solving it is adding a Theme to the bottom navigation call in activity, like this:
android:theme="?attr/toolbarNavigationButtonStyle"
I have no clue why it works, but it solves the issue apparently in lots of devices exept in Samsung Galaxy Note 8
Here is "bnv_tab_item_foreground"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/colorAccent" />
<item android:color="@android:color/darker_gray" />
</selector>