Listview selector with colored background and ripple effect

后端 未结 6 1052
误落风尘
误落风尘 2020-12-07 12:27

Standard ListView selector in android L developer preview uses colorControlHighlight for the ripple effect on touch and has a transparent backgroun

6条回答
  •  天涯浪人
    2020-12-07 13:09

    As far as I can tell this bug is only in Android 5.0, not 5.1. The trick seems to be to use Drawable#setHotspot as a Google dev hints to here https://twitter.com/crafty/status/561768446149410816 (because obscure twitter hints are a great form of documentation!)

    Assume you have a row layout something like this

    
    
          
    
              .... content here .....
    
         
    
    
    

    The following worked for me

                row.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        v.findViewById(R.id.row_content)
                            .getBackground()
                            .setHotspot(event.getX(), event.getY());
    
                        return(false);
                    }
                });
    

提交回复
热议问题