How to Create a Transparent Activity in Android?


Many applications require transparent activity inside our Android application. In this article, we will take a look at creating transparent activity in Android application

What are we going to build in this article?

We will build a simple application that displays a simple list in transparent activity. In the transparent activity, we will be adding different styles to our project. we are going to implement this project using the Kotlin language.


Here is the step by step Implementation process:


Step 1: Create a new project in Android  or you can use an already created project.  



Step 2: Add permission to the internet  in app> Androidmanifest.xml file and below code.(optional)


 <uses-permission android:name="android.permission.INTERNET" />

Step 3: Create an activity_main.xml file in your layout folder .

 implement the same invoke the following code inside activity_main.xml file.

 <?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:id="@+id/idRLContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginTop="80dp"
android:text="Candidroot solutions"
android:textAlignment="center"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.842"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/text_view_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/button_1"
android:layout_centerHorizontal="true"
android:layout_marginTop="72dp"
android:text="0"
android:textSize="50sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtTitle" />

<Button
android:id="@+id/button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="112dp"
android:text="click"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view_1" />
 </androidx.constraintlayout.widget.ConstraintLayout>
Step 4: Create an activity_main.kt file in your package folder .

 implement the same invoke the following code inside activity_main.kt file.

 import android.os.Bundle;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonsend = findViewById(R.id.button_1);

buttonsend.setOnClickListener(v -> {
StaticMethod.displayToast(MainActivity.this, getString(R.string.app_name));
});

}

}

Happy coding!

365Bloggy May 23, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive