开发者

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

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 wo开发者_JAVA技巧rk but maybe not the best way?


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
    }
});


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


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


You can also use

android:background = "@null"


There's:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜