像android中的常规按钮一样的隐形/透明按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3775726/
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-08-20 12:06:24  来源:igfitidea点击:

Invisible / transparent button that works like a regular in android?

androidimagebuttoninvisible

提问by Xtreme

How do I get one area in the middle of a image clickable (not the whole image)? Tried with a button set to invisible and clickable but the button does not work. What are the alternatives to an invisible / transparent button that works like a regular?

如何使图像中间的一个区域可点击(不是整个图像)?尝试将按钮设置为不可见和可点击,但该按钮不起作用。像常规一样工作的隐形/透明按钮有哪些替代方案?

I've also thought of a completely transparent and clickable PNG that should work but maybe not the best way?

我还想到了一个完全透明且可点击的 PNG 应该可以工作,但可能不是最好的方法?

回答by ingh.am

Here you go:

干得好:

Button theButton = (Button)findViewById(R.id.theButton);
theButton.setVisibility(View.VISIBLE);
theButton.setBackgroundColor(Color.TRANSPARENT);

phoneButton.setOnClickListener(new OnClickListener()
{   
    @Override
    public void onClick(View v)
    {
        // DO STUFF
    }
});

回答by Srinath Ganesh

android:background="@android:color/transparent"

回答by Konstantin Burov

You can try set transparent background to the button. But do not change buttons visibility, cause that prevents view from getting click events.

您可以尝试为按钮设置透明背景。但是不要改变按钮的可见性,因为这会阻止视图获得点击事件。

回答by ZanoOnStack

You can also use

你也可以使用

android:background = "@null"

回答by Christian

There's:

有:

android:background="?android:attr/selectableItemBackground"