Android通过xml文件实现复合按钮

发布于 2024-12-14 21:32:59 字数 325 浏览 4 评论 0原文

我正在尝试使用android的内置控件CompoundButton,但是我没有运气在xml中使用它,这是我的代码,

<CompoundButton
    android:id="@+id/mini_recorder_play"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_weight="1"
    android:background="@drawable/play_d" />

它在膨胀时抛出异常。

I am trying to use android's built in control CompoundButton, however I have no luck using it in xml, here is my code

<CompoundButton
    android:id="@+id/mini_recorder_play"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_weight="1"
    android:background="@drawable/play_d" />

it is throwing exception while inflating.

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

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

发布评论

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

评论(1

溺孤伤于心 2024-12-21 21:32:59

CompoundButton 是一个抽象类,不能直接实例化它。您必须实例化其子类之一(例如 CheckBoxRadioButtonToggleButton),或者如果这些小部件都不适合您,则创建您自己的自定义子类。需要。

华泰

CompoundButton is an abstract class, you cannot instantiate it directly. You must either instantiate one of its subclasses (e.g. CheckBox, RadioButton, ToggleButton) or create your own customized subclass if none of those widgets fits your needs.

HTH

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