From 9aa70c256acd336cf395e7ccc78a8796996d41ab Mon Sep 17 00:00:00 2001 From: chenshixin Date: Tue, 20 Sep 2016 10:40:15 +0800 Subject: [PATCH] Add interface to set badge drawable --- .../chenshixin/bottomnavigation/BottomNavigation.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bottom-navigation/src/main/java/com/chenshixin/bottomnavigation/BottomNavigation.kt b/bottom-navigation/src/main/java/com/chenshixin/bottomnavigation/BottomNavigation.kt index 7784c37..83adb6d 100644 --- a/bottom-navigation/src/main/java/com/chenshixin/bottomnavigation/BottomNavigation.kt +++ b/bottom-navigation/src/main/java/com/chenshixin/bottomnavigation/BottomNavigation.kt @@ -1,8 +1,9 @@ package com.chenshixin.bottomnavigation import android.content.Context +import android.graphics.drawable.Drawable import android.support.design.widget.CoordinatorLayout -import android.support.v4.app.FragmentStatePagerAdapter +import android.support.v4.app.FragmentPagerAdapter import android.util.AttributeSet import android.view.LayoutInflater import android.view.ViewGroup @@ -46,8 +47,10 @@ class BottomNavigation(context: Context?, attrs: AttributeSet?) : CoordinatorLay layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) } - fun setFragmentPagerAdapter(fragmentPagerAdapter: FragmentStatePagerAdapter) { + fun setFragmentPagerAdapter(fragmentPagerAdapter: FragmentPagerAdapter) { bottom_navigation_view_pager.adapter = fragmentPagerAdapter + //Cache all pages + bottom_navigation_view_pager.offscreenPageLimit = fragmentPagerAdapter.count - 1 } fun setTabItems(tabs: List) { @@ -86,6 +89,10 @@ class BottomNavigation(context: Context?, attrs: AttributeSet?) : CoordinatorLay bottom_navigation_bar.tabs[index].setBadgeNumber(number) } + fun setBadgeDrawable(drawable: Drawable) { + bottom_navigation_bar.setBadgeBackground(drawable) + } + fun setItemTitle(index: Int, title: String) { bottom_navigation_bar.tabs[index].setTitle(title) }