I want to use MaterialButtonToggleGroup
with 2 MaterialButton
. I want to display them with same width inside MaterialButtonToggleGroup
If I use match_parent
then only one button will be displayed and if I use wrap_content
they displayed in the middle.
Below is the current output
Below is my code :-
<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
Just faced an issue myself, starting version 1.1.0-beta01, MaterialButtonToggleGroup
is extending LinearLayout
so equal width for buttons can be set like this (assuming default 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With