1. 程式人生 > 其它 >BottomNavigationView 去掉選單長按 彈出選單文字吐司,去掉水波紋

BottomNavigationView 去掉選單長按 彈出選單文字吐司,去掉水波紋

方法1

//去掉長按吐司
        val bottomNavView: View = bottomNavigationView.getChildAt(0)
        bottomNavView.findViewById<View>(R.id.action_home).setOnLongClickListener { true }
        bottomNavView.findViewById<View>(R.id.action_room).setOnLongClickListener { true }
        bottomNavView.findViewById<View>(R.id.action_device).setOnLongClickListener { true }
        bottomNavView.findViewById<View>(R.id.action_smart).setOnLongClickListener { true }
        bottomNavView.findViewById<View>(R.id.action_personal).setOnLongClickListener { true }

方法2

 private fun initBottomNavigationView() {
        val ids = ArrayList<Int>()
        ids.add(R.id.action_home)
        ids.add(R.id.action_room)
        ids.add(R.id.action_device)
        ids.add(R.id.action_smart)
        ids.add(R.id.action_personal)
        clearToast(bottomNav,ids);
    }

    private fun clearToast(bottomNavigationView:BottomNavigationView, ids: ArrayList<Int>) {
        val bottomNavigationMenuView = bottomNavigationView.getChildAt(0) as ViewGroup
        //遍歷子View,重寫長按點選事件
        for (position in 0 until ids.size){
            bottomNavigationMenuView.getChildAt(position).findViewById<View>(ids[position]).setOnLongClickListener { true }
        }
    }

 去掉點選水波效果

app:itemBackground設定背景顏色為白色
app:itemBackground="@color/white"