Android में फुल स्क्रीन डायलॉग बनाने का तरीका
यह ट्यूटोरियल दिखाता है कि एक डायलॉग को पूरी स्क्रीन पर कैसे प्रदर्शित किया जाए, जिसमें कोई टाइटल बार न हो। यह कस्टम फुल-स्क्रीन मॉडल बनाने के लिए उपयोगी है।
चरण 1: नया प्रोजेक्ट बनाएं
Android Studio में File → New Project चुनकर प्रोजेक्ट बनाएं।
चरण 2: लेआउट फ़ाइल (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">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:onClick="ClickHere"
android:text="Click here" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Hello World" />
</RelativeLayout>
चरण 3: MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void ClickHere(View view) {
Dialog dialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
dialog.setContentView(R.layout.activity_main);
dialog.show();
}
}
चरण 4: 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>
बेहतर विकल्प: DialogFragment उपयोग करें
आधुनिक Android विकास में Dialog के बजाय DialogFragment उपयोग करने की सलाह दी जाती है क्योंकि यह लाइफसाइकिल को बेहतर तरीके से संभालता है और कॉन्फिगरेशन परिवर्तनों (जैसे स्क्रीन रोटेशन) पर क्रैश नहीं होता।