Android: How to prevent any touch events from being passed from a view to the one underneath it?

前端 未结 8 725
深忆病人
深忆病人 2021-01-31 13:38

Specifically using the code below, is there a way to modify it so that the activity under this newly created view does not receive any gestures?

View v1 = new Vi         


        
8条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 14:06

    From code

    View v1 = new View(this);   
    v1.setClickable(true);
    v1.setFocusable(true);
    

    OR

    From xml

    
    

    This will prevent touch and click events from being propagated to views that stay below your view.
    Or if you inflate the View then to .xml add android:clickable="true"

提交回复
热议问题