使用反馈突出显示自定义android视图“tappable”

时间:2022-11-03 08:29:44

I'm using a custom view expanded from a XML layout in a horizontal scroll view as a sort of horizontal image list but I'm not sure how to get them to appear clickable/tappable (ie they highlight when tapped) or how to capture these events. I think I've tried setOnClickHandler without it working. I'm also trying to get a simple TextView to do the same. I've also tried setting android:clickable="true" but that hasn't helped either. Any ideas?

我正在使用从水平滚动视图中的XML布局扩展的自定义视图作为一种水平图像列表,但我不确定如何让它们显示为可点击/可点击(即,在点击时突出显示)或如何捕获这些事件。我想我已经尝试过setOnClickHandler而不用它。我也试图让一个简单的TextView做同样的事情。我也试过设置android:clickable =“true”,但这也没有帮助。有任何想法吗?

1 个解决方案

#1


0  

To take care of the visual feedback use an xml Selector, and set it as the View's background.

要处理视觉反馈,请使用xml选择器,并将其设置为视图的背景。

To handle click events use

要处理点击事件,请使用

mView.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        //your code here
    }
});

#1


0  

To take care of the visual feedback use an xml Selector, and set it as the View's background.

要处理视觉反馈,请使用xml选择器,并将其设置为视图的背景。

To handle click events use

要处理点击事件,请使用

mView.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        //your code here
    }
});