How to prevent Button inside ListItem getting highlight

不羁岁月 提交于 2019-11-29 04:40:19
AlexGuti

I found out that setting android:clickable="true" to the parent view will prevent child views state to be changed.

See this answer.

This makes my app work harder, but it solves the problem:

...
mImageIcon.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                v.setBackgroundResource(R.drawable.my-background);
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                /*
                 * You can use another background rather than 0.
                 */
                v.setBackgroundResource(0);
                break;
            }

            return false;
        }// onTouch()
    });

I have this problem too, I Google it and try it about 3 hours! now I found the solution. just add OnClickListener to child view. and even DO NOTHING in OnClick method. It works on 2.3 emulator and my nexus 5.

im my opinion you need to disable the state from the parent as android:duplicateParentState="false"

add this to your Button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!