Invisible / transparent button that works like a r

2019-02-04 06:40发布

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?

5条回答
闹够了就滚
2楼-- · 2019-02-04 07:07

You can also use

android:background = "@null"
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-02-04 07:18

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
    }
});
查看更多
对你真心纯属浪费
4楼-- · 2019-02-04 07:21

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

查看更多
走好不送
5楼-- · 2019-02-04 07:29
android:background="@android:color/transparent"
查看更多
爷的心禁止访问
6楼-- · 2019-02-04 07:32

There's:

android:background="?android:attr/selectableItemBackground"
查看更多
登录 后发表回答