直接把音乐写到android应用程序里

1.首先介绍一下,整个结构图

  

2.activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/b2"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:onClick="onClick"
        android:text="一起摇摆-汪峰" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:onClick="onClick"
        android:text="自由自在-凤凰传奇" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:onClick="onClick"
        android:text="有没有一首歌" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:onClick="onClick"
        android:text="Moten Harket" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:onClick="onClick"
        android:text="漂洋过海来看你" />

    <Button
        android:id="@+id/button6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:onClick="onClick"
        android:text="信仰-张信哲" />

    <Button
        android:id="@+id/button7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:onClick="onClick"
        android:text="撕夜—阿杜" />

    <Button
        android:id="@+id/button8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:onClick="onClick"
        android:text="手心里的爱" />

    <Button
        android:id="@+id/button9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:onClick="onClick"
        android:text="男人海洋-周传雄" />

    <Button
        android:id="@+id/button10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:onClick="onClick"
        android:text="林俊杰-江南" />

</LinearLayout>


小点:

(1)设置背景颜色

                android:background="@drawable/b2"

(2)设置按钮为透明的

             android:background="#00000000"

3.MainActivity

package com.fengjia.music;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;

public class MainActivity extends Activity {

	private Button  button1,button2, button3, button4, button5, button6, button7,
			button8, button9, button10;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//隐藏标题
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		
		
		final Intent ziyouzizai = new Intent(MainActivity.this,
				Ziyouzizai.class);
		final Intent nanrenhaiyang = new Intent(MainActivity.this,
				Nanrenhaiyang.class);
		final Intent xinyang = new Intent(MainActivity.this, Xinyang.class);
		final Intent yiqiyaobai = new Intent(MainActivity.this,
				Yiqiyaobai.class);
		final Intent youmeiyouyishouge = new Intent(MainActivity.this,
				Youmeiyouyishouge.class);
		final Intent motenharket = new Intent(MainActivity.this,
				Motenharket.class);
		final Intent piaoyangguohai = new Intent(MainActivity.this,
				Piaoyangguohai.class);
		final Intent siye = new Intent(MainActivity.this, Siye.class);
		final Intent shouxinlideai = new Intent(MainActivity.this,
				Shouxinlideai.class);
		final Intent zhuzhige = new Intent(MainActivity.this, Jiangnan.class);

		// ------一起摇摆------
		button1 = (Button) findViewById(R.id.button1);
		button1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				startService(yiqiyaobai);
				stopService(ziyouzizai);
				stopService(youmeiyouyishouge);
				stopService(motenharket);
				stopService(piaoyangguohai);
				stopService(xinyang);
				stopService(siye);
				stopService(shouxinlideai);
				stopService(nanrenhaiyang);
				stopService(zhuzhige);
			

			}

		});
		// ------自由自在------
		button2 = (Button) findViewById(R.id.button2);
		button2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				stopService(yiqiyaobai);
				startService(ziyouzizai);
				stopService(youmeiyouyishouge);
				stopService(motenharket);
				stopService(piaoyangguohai);
				stopService(xinyang);
				stopService(siye);
				stopService(shouxinlideai);
				stopService(nanrenhaiyang);
				stopService(zhuzhige);
				

			}

		});
		// ------有没有一首歌------
		button3 = (Button) findViewById(R.id.button3);
		button3.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				stopService(yiqiyaobai);
				stopService(ziyouzizai);
				startService(youmeiyouyishouge);
				stopService(motenharket);
				stopService(piaoyangguohai);
				stopService(xinyang);
				stopService(siye);
				stopService(shouxinlideai);
				stopService(nanrenhaiyang);
				stopService(zhuzhige);
			

			}

		});
		// ------Moten Harket------
		button4 = (Button) findViewById(R.id.button4);
		button4.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				stopService(yiqiyaobai);
				stopService(ziyouzizai);
				stopService(youmeiyouyishouge);
				startService(motenharket);
				stopService(piaoyangguohai);
				stopService(xinyang);
				stopService(siye);
				stopService(shouxinlideai);
				stopService(nanrenhaiyang);
				stopService(zhuzhige);
			

			}

		});
		// ------漂洋过海来看你------
		button5 = (Button) findViewById(R.id.button5);
		button5.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				stopService(yiqiyaobai);
				stopService(ziyouzizai);
				stopService(youmeiyouyishouge);
				stopService(motenharket);
				startService(piaoyangguohai);
				stopService(xinyang);
				stopService(siye);
				stopService(shouxinlideai);
				stopService(nanrenhaiyang);
				stopService(zhuzhige);
				

			}

		});
		// ------信仰------
		button6 = (Button) findViewById(R.id.button6);
		button6.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				stopService(yiqiyaobai);
				stopService(ziyouzizai);
				stopService(youmeiyouyishouge);
				stopService(motenharket);
				stopService(piaoyangguohai);
				startService(xinyang);
				stopService(siye);
				stopService(shouxinlideai);
				stopService(nanrenhaiyang);
				stopService(zhuzhige);

				

			}

		});
		// ------撕夜------
		button7 = (Button) findViewById(R.id.button7);
		button7.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				stopService(yiqiyaobai);
				stopService(ziyouzizai);
				stopService(youmeiyouyishouge);
				stopService(motenharket);
				stopService(piaoyangguohai);
				stopService(xinyang);
				startService(siye);
				stopService(shouxinlideai);
				stopService(nanrenhaiyang);
				stopService(zhuzhige);
				

			}

		});
		// ------手心里的爱------
		button8 = (Button) findViewById(R.id.button8);
		button8.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				stopService(yiqiyaobai);
				stopService(ziyouzizai);
				stopService(youmeiyouyishouge);
				stopService(motenharket);
				stopService(piaoyangguohai);
				stopService(xinyang);
				stopService(siye);
				startService(shouxinlideai);
				stopService(nanrenhaiyang);
				stopService(zhuzhige);
				
			}

		});
		// ------男人海洋------
		button9 = (Button) findViewById(R.id.button9);
		button9.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				stopService(yiqiyaobai);
				stopService(ziyouzizai);
				stopService(youmeiyouyishouge);
				stopService(motenharket);
				stopService(piaoyangguohai);
				stopService(xinyang);
				stopService(siye);
				stopService(shouxinlideai);
				startService(nanrenhaiyang);
				stopService(zhuzhige);
				

			}

		});
		// ------江南------
		button10 = (Button) findViewById(R.id.button10);
		button10.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				stopService(yiqiyaobai);
				stopService(ziyouzizai);
				stopService(youmeiyouyishouge);
				stopService(motenharket);
				stopService(piaoyangguohai);
				stopService(xinyang);
				stopService(siye);
				stopService(shouxinlideai);
				stopService(nanrenhaiyang);
				startService(zhuzhige);
				

			}

		});

	}
}

4.AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fengjia.music"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.fengjia.music.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         //注册一起摇摆
        <service android:name="com.fengjia.music.Yiqiyaobai" >
        </service>
        //注册自由自在
        <service android:name="com.fengjia.music.Ziyouzizai" >
        </service>
        //注册有没有一首歌会让你记起我
        <service android:name="com.fengjia.music.Youmeiyouyishouge" >
        </service>
        //注册Moten harket
        <service android:name="com.fengjia.music.Motenharket" >
        </service>
        //注册漂洋过海来看你
        <service android:name="com.fengjia.music.Piaoyangguohai" >
        </service>
        //注册 信仰
        <service android:name="com.fengjia.music.Xinyang" >
        </service>
        //注册 撕夜
        <service android:name="com.fengjia.music.Siye" >
        </service>
        //注册 手心里的爱
        <service android:name="com.fengjia.music.Shouxinlideai" >
        </service>
        //注册男人海洋
        <service android:name="com.fengjia.music.Nanrenhaiyang" >
        </service>
        //注册 江南
        <service android:name="com.fengjia.music.Jiangnan" >
        </service>
 
    </application>

</manifest>

5.几个链接

  (1)源代码  代码下载
 (2)透明或半透明  点击打开链接
 (3)有问题多多交流 




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值