隐形/透明按钮,像Android中的常规一样工作?

Xtr*_*eme 27 android invisible image button

如何在图像中间点击一个区域(不是整个图像)?尝试按钮设置为不可见和可点击但按钮不起作用.隐形/透明按钮有哪些替代方案可以像普通按钮一样工作?

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

ing*_*.am 24

干得好:

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
    }
});
Run Code Online (Sandbox Code Playgroud)

  • 另外,使用XML布局属性:`android:background ="@ android:color/transparent"`. (11认同)
  • 您可能还需要一件事(例如,一个不可见的复活节彩蛋按钮)是“ theButton.setTextColor(Color.TRANSPARENT);”。 (2认同)

Sri*_*esh 19

android:background="@android:color/transparent"
Run Code Online (Sandbox Code Playgroud)


Kon*_*rov 6

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