先上BottomNavigationBar的下载地址:
https://github.com/Ashok-Varma/BottomNavigation
相信大家都用过,在此就不做使用详述;
但是会发现此控件并不支持设置背景图,只能设置背景色;如果有这样的需求怎么办?
问题总比办法多,我们来看一下源码:

好的,我们找到了设置背景色的变量:mBackgroundColor,让我们看一下他赋值给了谁

好的,赋值给了mContainer,那么mContainer是个什么呢?发现是一个FrameLayout,好的,我们继续找mContainer在哪个地方实例化

至此,我们知道了mContainer的id:bottom_navigation_bar_container;那么问题到此就差不多解决了;
FrameLayout mFrameLayout = (FrameLayout) mBottomNavigationBar.findViewById(com.ashokvarma.bottomnavigation.R.id.bottom_navigation_bar_container);//得到 mContainer
mFrameLayout.setBackgroundResource(id);//id:背景图id
到此,问题解决,记录于此
网友评论