Reputation: 59
The way that I have done in the code section. dynamically generted menu code.
for(int i = 0;i<menuDetails.size();i++){
int res_id = this.getResources().getIdentifier("@drawable/"+menuDetails.get(i).getMenu_icon(), null, this.getPackageName());
navigation.getMenu()
.add(Menu.NONE, i, Menu.NONE, menuDetails.get(i).getTitle())
.setIcon(res_id).setChecked(false)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
XML file:
<FrameLayout
android:id="@+id/home_footer"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_nav_height"
android:layout_alignParentBottom="true">
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_nav_height"
android:theme="@style/Widget.BottomNavigationView"
app:elevation="5dp"
app:itemIconTint="@drawable/nav_selection"
app:itemTextColor="@color/welcome_text_color"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent" />
<!-- app:itemIconTint="@drawable/nav_selection" -->
</FrameLayout>
nav_selection drawable file:
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/ic_call"/>
<item android:state_checked="false" android:drawable="@drawable/nav_case" />
output(actually the home button is another layout to fit into the centre, I need the icon like home button in the navigation View).
Upvotes: 2
Views: 266
Reputation: 714
Try to remove below the line
app:itemTextColor="@color/welcome_text_color"
Upvotes: 2
Reputation: 363439
In the BottomNavigationView
the app:itemIconTint
takes a ColorStateList
.
Each item must define an android:color
attribute, which may be an HTML-style hex color, a reference to a color resource, or -- in API 23 and above -- a theme attribute that resolves to a color.
Instead you are trying to use a StateListDrawable
and it doesn't work.
The only workaround to avoid tinting and use original icons is to use (app:itemIconTint="@null"
in the XML doesn't work)
bottomNavigationView.setItemIconTintList(null);
In any case I suggest not using it.
Upvotes: 1