我想使用带有2个MaterialButton
的MaterialButtonToggleGroup
。我想在MaterialButtonToggleGroup
中以相同的宽度显示它们
如果我使用match_parent
,那么只会显示一个按钮,如果我使用wrap_content
,它们会显示在中间。
下面是当前的输出
以下是我的代码:
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/toggle_button_group"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:gravity="center"
app:checkedButton="@id/btn_login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:singleSelection="true">
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_login"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_register"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register" />
</com.google.android.material.button.MaterialButtonToggleGroup>```
Please help. Thanks
发布于 2020-05-22 15:57:15
我刚刚遇到了一个问题,从1.1.0-beta01版本开始,MaterialButtonToggleGroup
扩展了LinearLayout
,所以可以像这样设置按钮的等宽(假设默认android:orientation="horizontal"
):
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/toggleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parrent"
android:text="Button 1"
style="?attr/materialButtonOutlinedStyle"
/>
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parrent"
android:text="Button 2"
style="?attr/materialButtonOutlinedStyle"
/>
</com.google.android.material.button.MaterialButtonToggleGroup>
https://stackoverflow.com/questions/56407933
复制相似问题