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

এন্ড্রয়েডে TextView-এর ফন্ট রঙ পরিবর্তন করার পদ্ধতি

এন্ড্রয়েডে TextView-এর ফন্ট রঙ পরিবর্তন করার ধাপাবলী

এই উদাহরণটি দেখায় কীভাবে একটি এন্ড্রয়েড অ্যাপ্লিকেশনে TextView-এর ফন্ট রঙ পরিবর্তন করা যায়। আমরা দুইটি ভিন্ন পদ্ধতি দেখব: পূর্বনির্ধারিত রঙ কনস্ট্যান্ট এবং হেক্স রঙ কোড ব্যবহার করে।

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

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

ধাপ ২: লেআউট ফাইল সংশোধন করুন (res/layout/activity_main.xml)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:tools="https://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="আমার রঙ নীল"
        android:layout_centerInParent="true"
        android:textStyle="bold"
        android:textSize="36sp"/>
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView1"
        android:layout_marginBottom="10dp"
        android:text="আমার রঙ সবুজ"
        android:textStyle="bold"
        android:layout_centerInParent="true"
        android:textSize="36sp" />
</RelativeLayout>

ধাপ ৩: মূল এক্টিভিটি লজিক যোগ করুন (src/MainActivity.java)

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        TextView textView1 = findViewById(R.id.textView1);
        textView1.setTextColor(Color.BLUE); // পূর্বনির্ধারিত রঙ কনস্ট্যান্ট
        
        TextView textView2 = findViewById(R.id.textView2);
        textView2.setTextColor(Color.parseColor("#006400")); // হেক্স রঙ কোড
    }
}

ধাপ ৪: ম্যানিফেস্ট ফাইল (AndroidManifest.xml)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android" package="app.com.sample">
    <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/AppTheme">
        <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 Studio-তে আপনার প্রজেক্টের এক্টিভিটি ফাইল খুলুন এবং টুলবারের Run আইকনে ক্লিক করুন। আপনার মোবাইল ডিভাইস নির্বাচন করুন এবং আপনার ডিভাইসে ডিফল্ট স্ক্রিন দেখুন।

  1. Android-এ রানটাইমে TextView-এর স্টাইল পরিবর্তন করার পদ্ধতি

  2. Android WebView-এ ফন্ট ফেস (Font Face) পরিবর্তন করার পদ্ধতি

  3. Android-এ কালার ইন্টিজারকে Hex String-এ কনভার্ট করা

  4. অ্যান্ড্রয়েড ListView-এর রঙ এবং ফন্ট কীভাবে পরিবর্তন করবেন?