Search code examples
androidandroid-fragmentsandroid-activityandroid-fragmentactivityintentfilter

How to create a Mini-Music Player (Activity or Fragment, etc.) in Android Studio


I am trying to develop/build my own music player App. There is this feature I see in almost every other Music Player Apps, and I want to do the same thing in my App. However I just don't know what it is called, I'm not sure if its a type of Fragment or a different kind of Activity, so I've included this image to show what I'm referring to.

enter image description here

This happens when you select a file using any File Explorer, instead of the actual Music Player starting, you get this small Activity or Fragment or Mini-Music Player...

I want to know what it is and just a basic explanation on how to create it, I can figure out the rest on my own.

Thanks.


Solution

  • So it took me a while but I finally figured it out... It is basically an Activity with a transparent background. To create this transparent activity, we need to create a custom style for this activity then change the theme in the AndroidManifest.xml file.

    Adding the custom style for this activity

    Navigate to the app>res>values>themes.xml and add the code below.

    <resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.WildFire91" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryVariant">@color/colorPrimaryDark</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>
    
    
    <style name="Theme.AppCompat.Transparent" parent="Theme.AppCompat.NoActionBar">
        <!--  custom style for the transparent activity-->
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@color/transparent</item>
    </style>
    

    make sure you set the windowBackground to a transparent color... the following is my colors.xml file

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="purple_200">#FFBB86FC</color>
        <color name="purple_500">#FF6200EE</color>
        <color name="purple_700">#FF3700B3</color>
        <color name="teal_200">#FF03DAC5</color>
        <color name="teal_700">#FF018786</color>
        <color name="black">#FF000000</color>
        <color name="white">#FFFFFFFF</color>
        <color name="colorPrimary">#1B1A1C</color>
        <color name="colorPrimaryDark">#151515</color>
        <color name="colorAccent">#FFFFFFFF</color>
        <color name="btnColor">#DE0000</color>
        <color name="fontColor1">#ECB8B8</color>
        <color name="fontColor2">#FADDDD</color>
    
          <!--  my transparent color-->
        <color name="seeThrough">#00000000</color>
    </resources>
    

    Changing the theme in the AndroidManifest.xml file

    <activity android:name=".MyTransparentActivity" android:theme="@style/Theme.AppCompat.Transparent">
            
     </activity>
    

    Results

    enter image description here