how to make activity transparent in Android
Android

How To Make Activity Transparent In Android?

2.4/5 - (5 votes)

Creating transparent activities sometimes may be so easy, yet so tricky. Don’t worry, this article will help you know how to make activity transparent in Android.

For example, when you use an Android app on your phone, the activity bar gets white/black. It can be irritating for you. Thus, you need to make a transparent activity to get a full-screen layout with a transparent status bar.

Building transparent activity looks easy from the outside, but it’s not so easy. So, scroll down and read through the article carefully.

how to make activity transparent in Android

What is status bar in Android?

You might have seen a row with some icons like battery information, time, app notification at the top of your Android screen, and it is called the status bar on Android. It is also known as the notification bar in Android.

The status bar on android shows your network status, minimized notifications battery status, device time, and other application notifications. Not only in Android, but you can also notice the status bar on iPhone.

How to make Activity Transparent in Android?

To make activity transparent in Android, you will need Android Studio software on your computer. We will build a new project simple program using Android Studio that will show a TestView over a transparent activity. That makes Android transparent activity over another app.

We will use the Kotlin programming language to implement the transparent activity. Don’t worry; we will give you the full code below. It’s not required to know Kotlin, and you just follow the steps below properly.

Tutorial to make activity transparent

Follow the method below accordingly to build activity transparent in Android Studio-

  • First, navigate to the res/value/themes.xml file and add themes.xml inside it

Code: themes.xml

<resources>

    <!– Base application theme. –>

        <style name=”Theme.AppCompat.transparent” parent=”Theme.AppCompat.NoActionBar”>

            <item name=”android:background”>#44000000</item>

            <item name=”android:windowNoTitle”>true</item>

            <item name=”android:windowBackground”>@android:color/transparent</item>

            <item name=”android:colorBackgroundCacheHint”>@null</item>

            <item name=”android:windowIsTranslucent”>true</item>

            <item name=”android:windowAnimationStyle”>@android:style/Animation</item>

        </style>

</resources>

  • Now, open the AndroidManifest.xml file  and change the theme name. ( You can change transparent color code Android from here)

Code: AndroidManifest.xml

<?xml version=”1.0″ encoding=”utf-8″?>

<manifest xmlns:android=”http://schemas.android.com/apk/res/android”

    package=”com.sagar.transparentactivityinandroid”>

    <application

        android:allowBackup=”true”

        android:icon=”@mipmap/ic_launcher”

        android:label=”@string/app_name”

        android:roundIcon=”@mipmap/ic_launcher_round”

        android:supportsRtl=”true”

        android:theme=”@style/Theme.AppCompat.transparent”>///change the theme name here //

        <activity android:name=”.MainActivity”>

            <intent-filter>

                <action android:name=”android.intent.action.MAIN” />

                <category android:name=”android.intent.category.LAUNCHER” />

            </intent-filter>

        </activity>

    </application>

</manifest>

  • Then, go to the res/layout/activity_main.xml and add the activity_main.xml code to it.

Code: activity_main.xml

<?xml version=”1.0″ encoding=”utf-8″?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android”

    xmlns:app=”http://schemas.android.com/apk/res-auto”

    xmlns:tools=”http://schemas.android.com/tools”

    android:layout_width=”match_parent”

    android:layout_height=”match_parent”

    tools:context=”.MainActivity”>

    <TextView

        android:id=”@+id/textView”

        android:layout_width=”wrap_content”

        android:layout_height=”wrap_content”

        android:gravity=”center_horizontal”

        android:text=”Developers Dome\nTransparent Activity”

        android:textAlignment=”center”

        android:textSize=”30sp”

        app:layout_constraintBottom_toBottomOf=”parent”

        app:layout_constraintLeft_toLeftOf=”parent”

        app:layout_constraintRight_toRightOf=”parent”

        app:layout_constraintTop_toTopOf=”parent” />

    <ImageView

        android:id=”@+id/imageView”

        android:layout_width=”0dp”

        android:layout_height=”wrap_content”

        android:layout_marginStart=”151dp”

        android:layout_marginLeft=”151dp”

        android:layout_marginEnd=”151dp”

        android:layout_marginRight=”151dp”

        android:layout_marginBottom=”62dp”

        android:src=”@drawable/ic_launcher_foreground”

        app:layout_constraintBottom_toTopOf=”@+id/textView”

        app:layout_constraintEnd_toEndOf=”parent”

        app:layout_constraintHorizontal_bias=”1.0″

        app:layout_constraintStart_toStartOf=”parent”

        app:layout_constraintTop_toTopOf=”parent”

        app:layout_constraintVertical_bias=”0.904″ />

</androidx.constraintlayout.widget.ConstraintLayout>

  • Go to src/MainActivity.kt and add the MainActivity.kt code to it.

Code: MainActivity.kt

package com.sagar.transparentactivityinandroid

import androidx.appcompat.app.AppCompatActivity

import android.os.Bundle

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_main)

    }

}

  • If you have finished the steps above, Run the program. (You can make Android activity semi transparent background editing the codes)
how to make activity transparent in Android

How do I change transparency on Android?

Transparency makes the UI look more aesthetic, and you can find many Transparent themes on Android. However, You can change the transparency on your Android by following some simple steps below-

  • Launch the Android Studio software on your PC.
  • Click on the Color option on the Android Studio editor
  • Give Alpha value with percentage
  • You will see XML which doubles values
  • For API 11+, the range is between 0f to 1f
  • Give values and see the results.

Conclusion

Hopefully, this guide on how to make activity transparent in Android has helped you to create transparent activity on Android. However, if it does not work for you, you might have done something wrong. Therefore, you should reread the instructions and follow them accordingly in this situation.

You may also have interested to know:

How to clear cache and cookies on Android phone

How to fix Google Talk authentication failed?

FAQs

1. How do you make an activity invisible?

You can create transparent activity in Android with Android Studio. That will make activity invisible on your phone while an app is running. You have to change and replace some codes inside the resource file. Following the guide above, you will understand everything.

2. What is Android overlay?

Overlay in Android means an app show content over another app on Android. If your phone doesn’t have this feature enabled, you can enable it from the Developers options.

3. How do I turn on Screen overlay on Android?

Follow the instructions below to turn on-screen overlay on Android-

  • Go to the Settings android application
  • Touch on the gear app from the settings page.
  • Scroll and find the Special Access option, then tap on it.
  • Toggle the Draw over other apps option from the list

Leave a Reply

Your email address will not be published.