隐形/透明按钮的工作方式与 Android 中的常规按钮类似吗?

发布于 2024-09-24 17:53:57 字数 129 浏览 2 评论 0原文

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

清君侧 2024-10-01 17:53:57

干得好:

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

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
    }
});
清醇 2024-10-01 17:53:57
android:background="@android:color/transparent"
android:background="@android:color/transparent"
深海夜未眠 2024-10-01 17:53:57

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

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

秋叶绚丽 2024-10-01 17:53:57

您还可以使用

android:background = "@null"

You can also use

android:background = "@null"
本王不退位尔等都是臣 2024-10-01 17:53:57

有:

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

There's:

android:background="?android:attr/selectableItemBackground"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文