目录
1.知识要点
使用Android Studio编写一个简单的音乐盒,要求音乐盒能够实现上一首、播放/暂停、停止、下一首的功能,同时显示播放歌曲的简单信息。(需要用到BroadcastReceiver组件,它是Android的四大组件之一,用来编写广播接收者程序,对广播做出响应。)
2.项目代码
2.1xml代码
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?><ImageButton
android:layout_margin="10dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/play"
android:id="@+id/play"/>
<ImageButton
android:layout_margin="10dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/stop"
android:id="@+id/stop"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/title"
android:marqueeRepeatLimit="marquee_forever"
android:layout_weight="1"
android:ellipsize="marquee"
android:textColor="#9C27B0"
android:textSize="25sp"
android:text="@string/app_name"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/author"
android:layout_weight="1"
android:textSize="25sp"
android:gravity="center_vertical"
android:text="@string/app_name"/>
</LinearLayout>