TextView में टेक्स्ट जस्टिफिकेशन
Android 8.0 (API 26) से android:justificationMode="inter_word" एट्रिब्यूट का उपयोग करके TextView में टेक्स्ट को जस्टिफाई (दोनों किनारों पर संरेखित) किया जा सकता है।
चरण 1: नया प्रोजेक्ट बनाएं
Android Studio में File → New Project चुनें (न्यूनतम API 26 या अधिक)।
चरण 2: लेआउट में दो TextView (activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/tvJustified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp"
android:textSize="20sp"
android:justificationMode="inter_word"
android:text="इस TextView में टेक्स्ट जस्टिफाई है। यह फीचर Android 8.0+ में आया। इस TextView में टेक्स्ट जस्टिफाई है। यह फीचर Android 8.0+ में आया।" />
<TextView
android:id="@+id/tvNotJustified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp"
android:textSize="20sp"
android:text="इस TextView में टेक्स्ट जस्टिफाई नहीं है। कोई जस्टिफिकेशन नहीं।" />
</LinearLayout>
चरण 3: MainActivity.java
package com.example.textjustify;
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);
}
}
चरण 4: AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="com.example.textjustify">
<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 8.0+), Run दबाएं, और पहले TextView में जस्टिफाई टेक्स्ट तथा दूसरे में सामान्य टेक्स्ट देखें।
