• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Need help adding sound to a button

sneharams

Lurker
Hello!
So I am very, very new to developing, and i'm trying to make a button. I've figured how to change the image of the button when clicked, but I don't know how to add my clicking sound.

Here are my xml codes for my button and the activity_main

button:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/pbutton"
android:state_pressed="true" />
<item android:drawable="@drawable/ubutton"
android:state_focused="true" />
<item android:drawable="@drawable/button" />
</selector>

activity_main:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30sp"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.one.sneha.MainActivity" >

<TextView
android:id="@+id/pointless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Pointless Button"
android:textColor="#FF0000"
android:textSize="30sp"
tools:ignore="HardcodedText" />


<Button
android:id="@+id/buttonp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/custombutton"
android:onClick="@raw/thozidaClick" />


<TextView
android:id="@+id/warning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/pointless"
android:layout_centerHorizontal="true"
android:text="warning: may be pointless"
android:textColor="#FF0000"
android:textSize="15sp"
tools:ignore="HardcodedText" />

</RelativeLayout>

Please Help!
Thank you!
 
Back
Top Bottom