কম্পিউটার

অ্যান্ড্রয়েডে একটি কাস্টম ডায়ালগ বক্স কীভাবে তৈরি করবেন?


এই উদাহরণটি দেখায় কিভাবে আমি Android এ একটি কাস্টম বার্তা তৈরি করব।

ধাপ 1 − অ্যান্ড্রয়েড স্টুডিওতে একটি নতুন প্রকল্প তৈরি করুন, ফাইল ⇒ নতুন প্রকল্পে যান এবং একটি নতুন প্রকল্প তৈরি করতে প্রয়োজনীয় সমস্ত বিবরণ পূরণ করুন

ধাপ 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">
   <TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="My Custom Message"
      android:textSize="22sp"
      android:textAlignment="center"
      android:layout_marginTop="30dp"
      android:id="@+id/myCustommessage"/>
   <Button
      android:layout_width="140dp"
      android:layout_height="80dp"
      android:layout_centerInParent="true"
      android:text="Show Message"
      android:backgroundTint="@color/colorPrimary"
      android:textSize="20dp"
      android:textColor="#ffffff"
      android:onClick="btn_showMessage" />
</RelativeLayout>

ধাপ 3 − প্রজেক্ট থেকে res-এ ক্লিক করুন → লেআউটে রাইট ক্লিক করুন → নতুন → লেআউট রিসোর্স ফাইল নির্বাচন করুন → লেআউটের নাম দিন =“কাস্টম_ডায়ালগ, “রুট এলিমেন্ট”-এ লিনিয়ার লেআউট লিখুন এবং ঠিক আছে ক্লিক করুন

পদক্ষেপ 4৷ - custom_dialog.xml

-এ নিম্নলিখিত কোড যোগ করুন
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
   android:orientation="vertical" android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:padding="15dp">
   <TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Enter your Message"
      android:textSize="22sp"
      android:textAlignment="center" />
   <EditText
      android:id="@+id/txt_input"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="10dp"
      android:hint="Enter your Message"
      android:textSize="20sp" />
   <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="15dp">
      <Button
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:backgroundTint="@color/colorPrimary"
         android:text="Cancel"
         android:textColor="#ffffff"
         android:textSize="18sp"
         android:layout_weight="1"
         android:id="@+id/btn_cancel"/>
     <Button
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:backgroundTint="@color/colorPrimary"
         android:text="Okay"
         android:textColor="#ffffff"
         android:textSize="18sp"
         android:layout_weight="1"
         android:id="@+id/btn_okay"/>
   </LinearLayout>
</LinearLayout>

ধাপ 5 − src/MainActivity.java

-এ নিম্নলিখিত কোড যোগ করুন
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
   TextView myCustomMessage;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      myCustomMessage = (TextView)findViewById(R.id.myCustommessage);
   }
   public void btn_showMessage(View view){
      final AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
      View mView = getLayoutInflater().inflate(R.layout.custom_dialog,null);
      final EditText txt_inputText = (EditText)mView.findViewById(R.id.txt_input);
      Button btn_cancel = (Button)mView.findViewById(R.id.btn_cancel);
      Button btn_okay = (Button)mView.findViewById(R.id.btn_okay);
      alert.setView(mView);
      final AlertDialog alertDialog = alert.create();
      alertDialog.setCanceledOnTouchOutside(false);
      btn_cancel.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            alertDialog.dismiss();
         }
      });
      btn_okay.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            myCustomMessage.setText(txt_inputText.getText().toString());
            alertDialog.dismiss();
         }
      });
      alertDialog.show();
   }
}

ধাপ 6 − 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>

আপনার অ্যাপ্লিকেশন চালানোর চেষ্টা করা যাক. আমি ধরে নিচ্ছি আপনি আপনার কম্পিউটারের সাথে আপনার আসল অ্যান্ড্রয়েড মোবাইল ডিভাইসটি সংযুক্ত করেছেন৷ অ্যান্ড্রয়েড স্টুডিও থেকে অ্যাপটি চালাতে, আপনার প্রোজেক্টের অ্যাক্টিভিটি ফাইলগুলির একটি খুলুন এবং টুলবার থেকে রান আইকনে ক্লিক করুন। একটি বিকল্প হিসাবে আপনার মোবাইল ডিভাইস নির্বাচন করুন এবং তারপরে আপনার মোবাইল ডিভাইসটি পরীক্ষা করুন যা আপনার ডিফল্ট স্ক্রীন প্রদর্শন করবে -

অ্যান্ড্রয়েডে একটি কাস্টম ডায়ালগ বক্স কীভাবে তৈরি করবেন?


অ্যান্ড্রয়েডে একটি কাস্টম ডায়ালগ বক্স কীভাবে তৈরি করবেন?


  1. একটি অ্যান্ড্রয়েড অ্যাপে কীভাবে একটি কাস্টম সতর্কতা ডায়ালগ তৈরি করবেন?

  2. অ্যান্ড্রয়েডে কাস্টম রেটিং বার কীভাবে তৈরি করবেন?

  3. অ্যান্ড্রয়েডে অ্যাকশনবারে কাস্টম ভিউ কীভাবে প্রদর্শন করবেন?

  4. কিভাবে Outlook এ একটি কাস্টম ভিউ তৈরি করবেন