문제

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!

도움이 되었습니까?

해결책

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;
        }
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top