Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android/Kotlin材质按钮组默认选择_Android_Kotlin_Material Design - Fatal编程技术网

Android/Kotlin材质按钮组默认选择

Android/Kotlin材质按钮组默认选择,android,kotlin,material-design,Android,Kotlin,Material Design,我在片段布局中有一个材质按钮切换组(需要单个选择和选择),但在加载我的应用程序时,我希望其中一个按钮已经被选择。我想把这个添加到我的主要活动onCreate()中就可以了(我的按钮id是paletteA): 但我的应用程序只是在loadtime上崩溃,运行窗口中不会显示任何错误。感觉有些东西没有及时加载或为空,即使我的所有片段都已加载,等等,这是我的onCreate()中的最后一件事。有什么想法吗?MaterialButtonToggleGroup小部件有一个名为app:checkedButto

我在片段布局中有一个材质按钮切换组(需要单个选择和选择),但在加载我的应用程序时,我希望其中一个按钮已经被选择。我想把这个添加到我的主要活动
onCreate()
中就可以了(我的按钮id是
paletteA
):


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

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分钟寻找名称中带有“selected”的属性。。。非常感谢。
<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">