Skip to main content
Título e tags editadas. Pequenas melhorias
Fonte Link
ramaral
  • 44,7mil
  • 14
  • 60
  • 110

Como mudar o estado de um ToggleButton alternarem entre siem java?

Criei este Drawable parapara definir como BackGroundBackground dos 6 ToggleButtonToggleButton. A minha pergunta e como

Como consigo fazer que os ToggleButtonToggleButton alternar entre eles sem serem clicados?

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

    <item android:state_checked="false" android:state_enabled="true" android:drawable="@drawable/cinquenta" /> 

    <item android:state_checked="true" android:state_enabled="true" android:drawable="@drawable/cinquentaum" />

    <item android:state_enabled="false" android:drawable="@drawable/cinquentadois" />
</selector>

ToggleButton alternarem entre si

Criei este Drawable para definir como BackGround dos 6 ToggleButton. A minha pergunta e como consigo fazer que os ToggleButton alternar entre eles sem serem clicados?

<item android:state_checked="false" android:state_enabled="true" android:drawable="@drawable/cinquenta" /> 

<item android:state_checked="true" android:state_enabled="true" android:drawable="@drawable/cinquentaum" />

<item android:state_enabled="false" android:drawable="@drawable/cinquentadois" />

Como mudar o estado de um ToggleButton em java?

Criei este Drawable para definir como Background dos 6 ToggleButton.

Como consigo fazer os ToggleButton alternar entre eles sem serem clicados?

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

    <item android:state_checked="false" android:state_enabled="true" android:drawable="@drawable/cinquenta" /> 

    <item android:state_checked="true" android:state_enabled="true" android:drawable="@drawable/cinquentaum" />

    <item android:state_enabled="false" android:drawable="@drawable/cinquentadois" />
</selector>
Fonte Link
sergiopm
  • 123
  • 1
  • 1
  • 9

ToggleButton alternarem entre si

Criei este Drawable para definir como BackGround dos 6 ToggleButton. A minha pergunta e como consigo fazer que os ToggleButton alternar entre eles sem serem clicados?

<item android:state_checked="false" android:state_enabled="true" android:drawable="@drawable/cinquenta" /> 

<item android:state_checked="true" android:state_enabled="true" android:drawable="@drawable/cinquentaum" />

<item android:state_enabled="false" android:drawable="@drawable/cinquentadois" />

<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/toggleButton1"
            android:layout_weight="1"
            android:background="@drawable/switch_icon"
            android:text=""
            android:textOff=""
            android:textOn=""/>

        <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/toggleButton2"
            android:layout_weight="1"
            android:background="@drawable/switch_icon"
            android:text=""
            android:textOff=""
            android:textOn=""/>

        <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/toggleButton3"
            android:layout_weight="6"
            android:background="@drawable/switch_icon"
            android:text=""
            android:textOff=""
            android:textOn=""/>

    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/toggleButton4"
            android:layout_weight="1"
            android:background="@drawable/switch_icon"
            android:text=""
            android:textOff=""
            android:textOn=""/>

        <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/toggleButton5"
            android:layout_weight="2"
            android:background="@drawable/switch_icon"
            android:text=""
            android:textOff=""
            android:textOn=""/>

        <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/toggleButton6"
            android:layout_weight="3"
            android:background="@drawable/switch_icon"
            android:text=""
            android:textOff=""
            android:textOn=""
            />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/toggleButton7"
            android:layout_weight="1"
            android:background="@drawable/switch_icon"
            android:text=""
            android:textOff=""
            android:textOn=""/>

        <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/toggleButton8"
            android:layout_weight="1"
            android:background="@drawable/switch_icon"
            android:text=""
            android:textOff=""
            android:textOn=""/>

        <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/toggleButton9"
            android:layout_weight="1"
            android:background="@drawable/switch_icon"
            android:text=""
            android:textOff=""
            android:textOn=""/>
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:text="score"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/score"
            android:layout_weight="1" />

        <TextView
            android:text="time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/time"
            android:layout_weight="1" />
    </LinearLayout>

</LinearLayout>