【问题标题】:Change Icon of BottomNavigationView on Runtime在运行时更改 BottomNavigationView 的图标
【发布时间】:2020-01-08 09:38:18
【问题描述】:

我想在我的 BottomNavigationView 初始化后更改它的图标。如果我在 onCreate 这样做,它工作正常。但是我必须在从服务器获得异步响应后才这样做。

val menuItem = bottom_navigation.menu.findItem(R.id.nav_item_4)
menuItem.icon = ContextCompat.getDrawable(this, R.drawable.ic_nav_message)

【问题讨论】:

标签: android bottomnavigationview android-navigationview material-components-android


【解决方案1】:

这可以让您选择在运行时更改图标。

MenuItem logOut= nav_Menu.findItem(R.id.nav_logOut);
logOut.setIcon(*here you can give the path of your icon*);

【讨论】:

  • 只有当我在 OnNavigationItemSelectListener 初始化之前调用它并且我的异步调用稍后才会出现时,它才会这样工作。
猜你喜欢
  • 2022-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多