仿小米应用商店底部按钮
<com.hxl.miuibottomnavigation.BottomNavigationView
android:layout_alignParentBottom="true"
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="70dp">
</com.hxl.miuibottomnavigation.BottomNavigationView>
findViewById<BottomNavigationView>(R.id.bottom)
.setClickListener(object : IItemClickListener {
override fun click(index: Int) {
}
})
.init(
NavigationBuild.Builder(this)
.addItem("首页", R.drawable.ic_home)
.addItem("娱乐", R.drawable.ic_game)
.addItem("我的", R.drawable.ic_me)
.setMode(Mode.MODE_SCROLL)
.setSelectTextColor(Color.RED)
.setFixedItems(mutableSetOf(1))
.build()
)
findViewById<BottomNavigationView>(R.id.bottom).setCurrentItem(3)
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<ViewPager>(R.id.viewpager).adapter = object : PagerAdapter() {
override fun getCount(): Int {
return 3
}
override fun isViewFromObject(view: View, `object`: Any): Boolean {
return view == `object`;
}
override fun instantiateItem(container: ViewGroup, position: Int): Any {
var arr = arrayListOf<Int>(Color.RED, Color.BLUE, Color.YELLOW)
var relativeLayout = RelativeLayout(this@MainActivity)
relativeLayout.setBackgroundColor(arr[position])
container.addView(relativeLayout)
return relativeLayout;
}
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
container.removeView(`object` as View)
}
}
findViewById<BottomNavigationView>(R.id.bottom)
.setClickListener(object : IItemClickListener {
override fun click(index: Int) {
}
})
.init(
NavigationBuild.Builder(this)
.addItem("首页", R.drawable.ic_home)
.addItem("娱乐", R.drawable.ic_game)
.addItem("我的", R.drawable.ic_me)
.setMode(Mode.MODE_NO_TITLE)
.setSelectTextColor(Color.RED)
.setupWithViewPager(findViewById(R.id.viewpager))
.setFixedItems(mutableSetOf(1))
.build()
)
}
}