Skip to content

Commit

Permalink
Save instance state
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshixin committed Aug 19, 2016
1 parent 19d0f1e commit 5282a29
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.chenshixin.bottomnavigation
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.os.Parcelable
import android.support.design.widget.CoordinatorLayout
import android.support.v4.view.ViewCompat
import android.support.v4.view.animation.LinearOutSlowInInterpolator
Expand Down Expand Up @@ -44,6 +46,25 @@ class BottomNavigationBar(context: Context, attrs: AttributeSet) : FrameLayout(c
LayoutInflater.from(context).inflate(R.layout.bottom_navigation_bar, this, true)
}

override fun onSaveInstanceState(): Parcelable {
val bundle = Bundle()
bundle.putParcelable("instanceState", super.onSaveInstanceState())
bundle.putInt("mCurrentTab", selectedPosition)
return bundle
}

override fun onRestoreInstanceState(stateParams: Parcelable) {
var state = stateParams
if (state is Bundle) {
selectedPosition = state.getInt("mCurrentTab")
state = state.getParcelable<Parcelable>("instanceState")
if (selectedPosition != 0 && bottom_navigation_bar_item_container.childCount > 0) {
setCurrentTab(selectedPosition)
}
}
super.onRestoreInstanceState(state)
}

fun initialise() {
if (items.isEmpty()) {
return
Expand Down

0 comments on commit 5282a29

Please sign in to comment.