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

Xtreme picture Xtreme · Sep 23, 2010 · Viewed 31.5k times · Source

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?

Answer

ingh.am picture ingh.am · Jan 27, 2011

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