यह उदाहरण दर्शाता है कि Android में TextView पर शैडो इफेक्ट कैसे जोड़ा जाए।
TextView पर शैडो इफेक्ट जोड़ने का उदाहरण
चरण 1 - नया प्रोजेक्ट बनाएं
Android Studio में एक नया प्रोजेक्ट बनाएं: File → New Project पर जाएं और आवश्यक विवरण भरें।
चरण 2 - लेआउट XML में कोड जोड़ें
res/layout/activity_main.xml में निम्नलिखित कोड जोड़ें:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="https://schemas.android.com/apk/res/android"
android:id="@+id/parent"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:textSize="28sp"
android:textAlignment="center"
android:textColor="#FFF"
android:layout_width="match_parent"
android:shadowColor="#000"
android:shadowDx="-2"
android:shadowDy="-2"
android:shadowRadius="1"
android:layout_height="wrap_content" />
</LinearLayout>
उपरोक्त कोड में, हमने TextView के साथ शैडो प्रॉपर्टीज ली हैं:
android:shadowColor="#000" android:shadowDx="-2" android:shadowDy="-2" android:shadowRadius="1"
उपरोक्त टैग TextView के लिए शैडो कलर, एक्सिस (X, Y) और शैडो रेडियस को दर्शाते हैं।
चरण 3 - MainActivity.java में कोड जोड़ें
src/MainActivity.java में निम्नलिखित कोड जोड़ें:
package com.example.andy.myapplication;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private TextView textview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview = findViewById(R.id.text);
textview.setText("TextView with shadow");
}
}
ऐप चलाएं
अपने Android डिवाइस को कंप्यूटर से कनेक्ट करें और ऐप चलाएं। परिणाम में TextView शैडो इफेक्ट के साथ दिखेगा।