Can someone please help me understand how to add a background color to my bottom navigation view. I have tried a multitude of things online. If I specify individual colors for each of background, itemBackground, itemIconTint etc. then it shows in the AS preview but doesn't reflect on the device when I launch the app. [The device has Android 8.0.0 on it].
If I use the style attribute then the BottomNavigationView vanishes from the AS preview and there is no difference in the application when I run it. I was successfully able to apply ripple effects to the icon clicks but this seems to completely stump me. And as per Android styles this should have worked. [https://developer.android.com/guide/topics/ui/look-and-feel/themes#Theme]
Code in styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBars">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="BottomNavigation" parent="AppTheme">
<item name="android:background">@color/colorAccent</item>
<item name="itemBackground">@drawable/bottom_navigation_colors</item>
<item name="itemIconTint">@drawable/navigation_bar_txt_color</item>
<item name="itemTextColor">@drawable/navigation_bar_txt_color</item>
</style>
</resources>
My Manifest has the following
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".screens.MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBars">
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN" />-->
<!--<category android:name="android.intent.category.LAUNCHER" />-->
<!--</intent-filter>-->
</activity>
<activity android:name=".screens.LoginActivity"
android:label="LoginActivity"
android:theme="@style/AppTheme.NoActionBars">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I tried using navigation.setBackgroundColor()
from the Java code and it worked for me.
But I still cannot get it to work using XML and styles. So will mark this as the answer for now, until a better answer explains why XML style isn't working.