How to Make Activity Transparent in Android? Step by Step Implementation Below:

You need to install an Android Studio application on your computer to create a new project file in Android Studio. After completing the installation Android Studio software you are ready to create Transparent Activity. Follow the step by step procedure below to create transparent activity in Android Studio:

First of all, to create new project open the Android Studio software, and then go to File>New Project. In this step, you will get some window fill up all window requirements to start new project. After that, add your needed code from here:

  • Add the Following Code: res/values/styles.xml and add themes.xml inside it.

<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>

  • Add the Following Code: xml to change the theme name and  Transparent color code).

<?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>

Transparent Preview Result Here:

Activity Transparent done result

 

  • Add the Following Code: kt to add the 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)

}

}

  • Add the Following Code: XML to add the 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>

Run the Program Now:

If you have completed all steps from the above section. Now it is time to run the program or expected output result. I think, if you fill all the steps carefully. It will be run successfully.

Comments