Android Seekbar - 当你增加一个 seekbar 时将所有 seekbar 设置为 0

Android Seekbar - put all seekbar at 0 when you increase a seekbar

我创建了一个在 activity 页面中包含 3 个搜索栏的应用程序。我想在移动搜索栏时将所有搜索栏设置为 0,如图所示。 screenshot apk

我试着把它作为一组切换按钮来做,但它不起作用。

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_options_page)

    image_lightr.setOnClickListener {
        finish()
    }
    val groupSeekBar = arrayOf(seekBar_global, seekBar_left, seekBar_right)
    val groupToggleButton = arrayOf(heart_toggle, dimming_toggle, chenillard_toggle)
    for (toggle in groupToggleButton){
        toggle.setOnCheckedChangeListener { v, isChecked ->
            if (isChecked)
                groupToggleButton.forEach { if (it !=toggle) it.isChecked = false }
        }
    }

    for (seekbar in groupSeekBar){
        seekbar.setOnSeekBarChangeListener{v, isChanged ->
            if(isChanged){
                groupSeekBar.forEach { if (it != seekbar) it.progress = false}
            }

        }
    }
    window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
    actionBar?.hide()
    supportActionBar?.hide()

}

您可以使用此代码:

        seekBar1.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener{
        override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {
            seekBar2.progress = 0
            seekBar3.progress = 0
        }

        override fun onStartTrackingTouch(p0: SeekBar?) {
            // Do nothing
        }

        override fun onStopTrackingTouch(p0: SeekBar?) {
            // Do nothing
        }

    })

    seekBar2.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener{
        override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {
            seekBar1.progress = 0
            seekBar3.progress = 0
        }

        override fun onStartTrackingTouch(p0: SeekBar?) {
            // Do nothing
        }

        override fun onStopTrackingTouch(p0: SeekBar?) {
            // Do nothing
        }

    })

    seekBar3.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener{
        override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {
            seekBar1.progress = 0
            seekBar2.progress = 0
        }

        override fun onStartTrackingTouch(p0: SeekBar?) {
            // Do nothing
        }

        override fun onStopTrackingTouch(p0: SeekBar?) {
            // Do nothing
        }

    })

这将是结果: