MainActivity.kt 1.46 KB
Newer Older
Nihar Thakkar's avatar
Nihar Thakkar committed
1
2
3
4
package io.eelo.appinstaller

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
5
6
7
8
9
import android.support.design.internal.BottomNavigationItemView
import android.support.design.internal.BottomNavigationMenuView
import android.support.design.widget.BottomNavigationView
import android.annotation.SuppressLint
import kotlinx.android.synthetic.main.activity_main.*
Nihar Thakkar's avatar
Nihar Thakkar committed
10
11
12
13
14
15

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
16
17

        removeShiftMode(bottom_navigation_view)
Nihar Thakkar's avatar
Nihar Thakkar committed
18
    }
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

    @SuppressLint("RestrictedApi")
    private fun removeShiftMode(bottomNavigationView: BottomNavigationView) {
        val menuView = bottomNavigationView.getChildAt(0) as BottomNavigationMenuView
        try {
            val mShiftingMode = menuView.javaClass.getDeclaredField("mShiftingMode")
            mShiftingMode.isAccessible = true
            mShiftingMode.setBoolean(menuView, false)
            mShiftingMode.isAccessible = false
        } catch (e: NoSuchFieldException) {
            e.printStackTrace()
        } catch (e: IllegalAccessException) {
            e.printStackTrace()
        }

        for (i in 0 until menuView.childCount) {
            val itemView = menuView.getChildAt(i) as BottomNavigationItemView
            itemView.setShiftingMode(false)
            itemView.setChecked(itemView.itemData.isChecked)
        }
    }

Nihar Thakkar's avatar
Nihar Thakkar committed
41
}