Android Studio: ToggleButton - How to start/awake with true instead of false?



-Using Android Studio


In my activity_main.xml,



android:checked="false"


would android:checked="" be the reason why my ToggleButton starts (or awakens) with false when my application compiles and runs? Changing to true seems to not work. My goal is to start with the ON button (or True) whenever my application boots instead of the OFF (or false) button but I have no idea how make this happen. Any ideas? Doesn't matter if it's through java or xml.


Also I am using,



android:background="@drawable/toggle_sound"


in order to import the images to the ToggleButton, which I successfully managed to do so.


In my toggle_sound.xml:



<item android:drawable="@drawable/sound_on" android:state_checked="true"></item>
<item android:drawable="@drawable/sound_off" android:state_checked="false"></item>


Additionally, this is my entire method of ToggleButton inside activity_main.xml:



<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/toggleSound"
android:background="@drawable/toggle_sound"
android:textOff=""
android:textOn=""
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_alignParentTop="true"
android:checked="false" />


Again, any solution either through java or xml will be much appreciated!


No comments:

Post a Comment