【问题标题】:Android/Kotlin Material Button Group default selectionAndroid/Kotlin Material Button Group 默认选择
【发布时间】:2021-06-02 13:00:45
【问题描述】:

我在 Fragment 布局中有一个 Material Button Toggle Group(需要单选和选择),但在加载我的应用程序时,我希望选择一个 已经 的按钮。我认为将其添加到我的主要活动 onCreate() 就可以了(我的按钮的 id 是 paletteA):

paletteA.isPressed = true

但我的应用程序只是在加载时崩溃,并且“运行”窗口中没有显示任何错误。感觉有些东西没有及时加载或为空,即使我的所有片段都已经加载等等,这是我onCreate() 中的最后一件事。有什么想法吗?

【问题讨论】:

    标签: android kotlin material-design


    【解决方案1】:

    MaterialButtonToggleGroup 小部件有一个名为 app:checkedButton 的 XML 属性,可用于加载选中的组中的按钮。

    要将MaterialButtonToggleGroup 中的特定按钮设置为默认加载为选中状态,请将要检查的按钮的id 作为值传递给app:checkedButton 属性。

    <com.google.android.material.button.MaterialButtonToggleGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:singleSelection="true"
            android:id="@+id/activity_main_togglebutton"
            app:checkedButton="@id/activity_main_button2">
    

    【讨论】:

    • !!我花了 20 分钟寻找名称中带有“已选择”的属性...谢谢!
    猜你喜欢
    • 1970-01-01
    • 2021-06-05
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    相关资源
    最近更新 更多