Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set ToggleButton to play default sound when clicked?

My android apps has a regular button:

<Button
  android:id="@+id/allOnButton"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_marginRight="130dp"
  android:text="@string/sensor_management_all_on" />

And a toggle button:

<ToggleButton
  android:id="@+id/accelerometerToggleButton"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:checked="true"
  android:textOff="off"
  android:textOn="on" />

When the button is pressed, a nice "click" sound is played, which gives a good feedback to the user that the button was actually pressed.

How do I set a click sound for the ToggleButton?

like image 873
Adam Matan Avatar asked Sep 16 '12 07:09

Adam Matan


1 Answers

For a click sound to be heard, you need clickListener to be set.

So set a dummy onClickListener onto the ToggleButton, it should play the sound effect.

like image 191
nandeesh Avatar answered Nov 19 '22 19:11

nandeesh