Android,为什么要使用 Button 视图,因为每个视图都可以有一个 onclicklistener

发布于 2024-12-06 18:39:20 字数 176 浏览 3 评论 0原文

我很好奇,为什么我要使用 Button 或 ImageButton,当 TextView、ImageView 和其他所有内容都可以有 onclicklisteners,所有内容都可以有 src 和背景属性、状态以及 Button 或 ImageButton 提供的其他所有内容时,

我可能会丢失一些东西,所以请透露它是什么

I am curious, why would I ever use Button or ImageButton, when TextViews, ImageViews, and everything else all can have onclicklisteners, all can have src's and background attributes, states and everything else that a Button or ImageButton offers

I might be missing something, so please reveal what it is

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

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

发布评论

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

评论(2

贩梦商人 2024-12-13 18:39:20

除了默认样式之外,没有任何区别。 ImageButton 默认情况下具有非空背景。

此外,ImageButton.onSetAlpha() 方法始终返回 false,scaleType 设置为 center 并且始终膨胀为可聚焦。

这是 ImageButton 的默认样式:

 <style name="Widget.ImageButton">
     <item name="android:focusable">true</item>
     <item name="android:clickable">true</item>
     <item name="android:scaleType">center</item>
     <item name="android:background">@android:drawable/btn_default</item>
 </style>

There's no differences, except default style. ImageButton has a non-null background by default.

Also, ImageButton.onSetAlpha() method always returns false, scaleType is set to center and it's always inflated as focusable.

Here's ImageButton's default style:

 <style name="Widget.ImageButton">
     <item name="android:focusable">true</item>
     <item name="android:clickable">true</item>
     <item name="android:scaleType">center</item>
     <item name="android:background">@android:drawable/btn_default</item>
 </style>
祁梦 2024-12-13 18:39:20

每个人都有不同的风格,仅此而已。您可以创建一个简单的 TextView,用户仍然可以单击它,并且您可以响应这些单击...但是 TextView 默认情况下不提供任何视觉反馈。

事实上,Button 只是一个带有一组选择器可绘制对象的 TextView

Each one has different styles, that's it. You can create a simple TextView and users still can click on it and you can respond to those clicks... but TextView does not offer by default any visual feedback.

In fact, a Button is just a TextView with a set of selector drawables.

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