এন্ড্রয়েডে TextView-এর ফন্ট পরিবার পরিবর্তন করার ধাপাবলী
এই উদাহরণটি দেখায় কীভাবে XML লেআউটে android:fontFamily অ্যাট্রিবিউট ব্যবহার করে 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="Hello World!"
android:fontFamily="cursive"
android:layout_centerInParent="true"
android:textSize="48sp" />
<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="Hello World"
android:layout_centerInParent="true"
android:fontFamily="sans-serif-black"
android:textSize="48sp"/>
</RelativeLayout>
ধাপ ৩: মূল এক্টিভিটি (src/MainActivity.java)
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
ধাপ ৪: ম্যানিফেস্ট ফাইল (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>
সাধারণ ফন্ট পরিবার অপশন
sans-serif- ডিফল্ট রোবটো ফন্টsans-serif-light- লাইট ওজনsans-serif-thin- থিন ওজনsans-serif-medium- মিডিয়াম ওজনsans-serif-black- ব্ল্যাক/বোল্ড ওজনserif- সেরিফ ফন্টmonospace- মনোস্পেস ফন্টcursive- কার্সিভ ফন্ট
অ্যাপ্লিকেশন চালান
আপনার আসল এন্ড্রয়েড ডিভাইস কম্পিউটারের সাথে সংযুক্ত আছে অনুমান করি। Android Studio-তে আপনার প্রজেক্টের এক্টিভিটি ফাইল খুলুন এবং টুলবারের Run আইকনে ক্লিক করুন। আপনার মোবাইল ডিভাইস নির্বাচন করুন এবং আপনার ডিভাইসে ডিফল্ট স্ক্রিন দেখুন।