কম্পিউটার টিউটোরিয়াল

Android-এ ট্রান্সপেরেন্ট (পারদর্শী) অ্যাক্টিভিটি তৈরি করার পদ্ধতি


Theme.AppCompat.Translucent ব্যবহার করে ট্রান্সপেরেন্ট অ্যাক্টিভিটি

এই উদাহরণটি দেখায় কিভাবে কাস্টম থিম ডিফাইন করে একটি অ্যাক্টিভিটিকে পুরোপুরি বা আংশিক পারদর্শী (Transparent) করা যায়।

ধাপ ১: নতুন প্রজেক্ট তৈরি করুন

Android Studio-তে File → New Project এ যান এবং প্রয়োজনীয় বিবরণ পূরণ করে একটি নতুন প্রজেক্ট তৈরি করুন।

ধাপ ২: styles.xml-এ ট্রান্সলুসেন্ট থিম ডিফাইন করুন

res/values/styles.xml ফাইলে নিচের কোডটি যোগ করুন:

<resources>
    <!-- Base application theme. -->
    <style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar">
        <!-- পারদর্শী ব্যাকগ্রাউন্ড (৩৩% অপাসিটি ব্ল্যাক) -->
        <item name="android:background">#33000000</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>

ধাপ ৩: লেআউট XML (activity_main.xml)

res/layout/activity_main.xml ফাইলে নিচের কোডটি যোগ করুন:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:app="https://schemas.android.com/apk/res-auto"
    xmlns:tools="https://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

ধাপ ৪: MainActivity.java

src/MainActivity.java ফাইলে নিচের কোডটি থাকবে:

package com.example.transparentactivity;

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

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

ধাপ ৫: AndroidManifest.xml-এ থিম অ্যাপ্লাই করুন

app/manifests/AndroidManifest.xml ফাইলে `` ট্যাগে `android:theme="@style/Theme.AppCompat.Translucent"` সেট করুন:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:tools="https://schemas.android.com/tools"
    package="com.example.transparentactivity">

    <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.Translucent"
        tools:ignore="GoogleAppIndexingWarning">

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

অ্যাপ্লিকেশন চালানোর পদ্ধতি

আপনার Android ডিভাইস কম্পিউটারের সাথে সংযুক্ত করুন। Android Studio-তে প্রজেক্টের activity ফাইল খুলে টুলবারের Run আইকনে ক্লিক করুন। আপনার মোবাইল ডিভাইস সিলেক্ট করুন। অ্যাপ খোলার সময় পেছনের স্ক্রিন/ওয়ালপেপার দেখা যাবে (পারদর্শী ইফেক্ট)।

Android-এ ট্রান্সপেরেন্ট (পারদর্শী) অ্যাক্টিভিটি তৈরি করার পদ্ধতি

  1. Facebook-এ Android অ্যাপ তৈরি করার পদ্ধতি

  2. অ্যান্ড্রয়েড অ্যাপে SurfaceView ট্রান্সপারেন্ট করবেন কীভাবে?

  3. অ্যান্ড্রয়েডে ট্রান্সপারেন্ট স্ট্যাটাসবার এবং একশনবার কীভাবে তৈরি করবেন?

  4. Android-এ মাল্টিলেভেল ListView (ExpandableListView) তৈরির পদ্ধতি