In this tutorial, we will learn how to create the Transparent Activity in the Android studio.
We will create a simple application that will display a simple TextView inside a transparent activity. We will add a different style to our activity in order to create a transparent activity. A sample video is provided below to give you an idea of what we will be doing in this article. It should be noted that we will be implementing this project in Kotlin.
Step 1 –> Add themes.xml in your res/value/themes.xml file.
File: 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>
Step 2 –> Change the name of the theme in the AndroidManifest.xml file.
File: 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>
Step 3 –> Add the activity_main.xml code to res/layout/activity_main.xml.
Step 4 − Add the MainActivity code to src/MainActivity.kt.
Step 5–> Run the program.
Preview: Transparent Activity
Learn Java Programming & get a Certificate
File: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) } }
File: 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>
- Let us try to run your android application, I’m assuming you’ve connected your Android smartphone to your PC. Open one of your project’s activity files and select Run Play Icon from the toolbar to run the app from Android Studio. Check your mobile device, which will display your default screen, after selecting it as an option.
Email Authentication Using Firebase in Android