nex3z / ToggleButtonGroup

A group of flowable toggle buttons, with multiple / single selection support and button customization.
Apache License 2.0
421 stars 48 forks source link

Add tbgUnmarkedColor #36

Closed YogevUzan closed 6 years ago

YogevUzan commented 6 years ago

Hi, can you please add these attributes ( XML )?

  1. tbgUnmarkedColor
  2. checked
nex3z commented 6 years ago
  1. You can add a background on the button as the unchecked image.

For example, add the folowing bg_unchecked.xml to /res/drawable:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid android:color="#cfd8dc"/>

    <size
        android:width="36dp"
        android:height="36dp"/>

</shape>

Then add bg_unchecked.xml to the button as background:

<com.nex3z.togglebuttongroup.SingleSelectToggleGroup
    android:id="@+id/group_choices"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tbgCheckedButton="@+id/choice_a">

    <com.nex3z.togglebuttongroup.button.CircularToggle
        android:id="@+id/choice_a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:background="@drawable/bg_unchecked"
        android:text="A"/>

    <com.nex3z.togglebuttongroup.button.CircularToggle
        android:id="@+id/choice_b"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:background="@drawable/bg_unchecked"
        android:text="B"/>

    <!--...-->

</com.nex3z.togglebuttongroup.SingleSelectToggleGroup>

The button will have a background for the unchecked state:

device-2018-08-01-223528

  1. What's the purpose of the checked attribute? If it's meant to set the button's default checked state, it may cause checked state collision in SingleSelectToggleGroup, as you can set two button to be checked by default where SingleSelectToggleGroup only allows one. I'm afraid I won't add this attribute to the built in button for simplicity as they are only samples for implementing custom buttons. You can always set button's checked state programmatically, or implement your own custom button with this attribute.