java Android 中 ImageButton 上的 ClickEvent?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2386402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:54:51  来源:igfitidea点击:

ClickEvent on ImageButton in Android?

javaandroidbutton

提问by harish

Is it possible to add a click event to an ImageButton?

是否可以向 ImageButton 添加单击事件?

回答by Hassy31

Yes it is! you can implement the onclick method like this

是的!你可以像这样实现 onclick 方法

ImageButton ib = (ImageButton)findViewById(R.id.imageButton);
    ib.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.v("ImageButton", "Clicked!");
        }
});

pls read documentationfor further details

请阅读文档以获取更多详细信息

回答by CommonsWare

Yes, it is possible. Here is a sample projectdemonstrating a View.OnClickListenerapplied to an ImageButton.

对的,这是可能的。这是一个示例项目,演示了View.OnClickListener应用于ImageButton.

回答by pfgrid