Question

I have 2 buttons overlapping with each other. Is it possible that when pressing the top button, the bottom button also showing its pressed state?

Thanks!

Was it helpful?

Solution

Button has a setPressed method which you could use in one of the buttons onClickListener to set the other button to a pressed state. You could then set an OnTouchListener on that button and listen for MotionEvent.ACTION_UP to set it back to a non pressed state.

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            button2.setPressed(true);
        }
});
button.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP)
                button2.setPressed(false);
            return false;
        }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top