কম্পিউটার

কিভাবে Android TextInputLayout বাস্তবায়ন করবেন


উদাহরণে আসার আগে, আমাদের জানা উচিত অ্যান্ড্রয়েডে TextInputLayout কি। TextInputLayout লিনিয়ার লেআউট দ্বারা প্রসারিত হয়। এটি পাঠ্য সম্পাদনা করার জন্য একটি মোড়ক হিসাবে কাজ করবে এবং পাঠ্য সম্পাদনার জন্য ফ্ল্যাটিং ইঙ্গিত অ্যানিমেশন দেখায়৷

এই উদাহরণটি কিভাবে Android TextInputLayout বাস্তবায়ন করতে হয় সে সম্পর্কে প্রদর্শন করে।

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

ধাপ 2 − res/layout/activity_main.xml-এ নিম্নলিখিত কোড যোগ করুন।

<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout 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"
   android:background = "#dde4dd"
   android:orientation = "vertical">
   <android.support.design.widget.TextInputLayout
      android:layout_width = "match_parent"
      android:layout_height = "wrap_content"
      android:id = "@+id/layoutEmail"
      android:layout_marginTop = "8dp"
      android:layout_marginStart = "8dp"
      android:layout_marginEnd = "8dp"
      style = "@style/Widget.MaterialComponents.TextInputLayout.FilledBox">
      <android.support.design.widget.TextInputEditText
         android:layout_width = "match_parent"
         android:layout_height = "wrap_content"
         android:id = "@+id/email"
         android:hint = "Enter Email id"
         android:inputType = "textEmailAddress"/>
   </android.support.design.widget.TextInputLayout>
   <android.support.design.widget.TextInputLayout
      android:layout_width = "match_parent"
      android:layout_height = "wrap_content"
      android:id = "@+id/layoutPassword"
      android:layout_marginTop = "8dp"
      android:layout_marginStart = "8dp"
      android:layout_marginEnd = "8dp"
      style = "@style/Widget.MaterialComponents.TextInputLayout.FilledBox">
      <android.support.design.widget.TextInputEditText
         android:layout_width = "match_parent"
         android:layout_height = "wrap_content"
         android:id = "@+id/password"
         android:hint = "Password"
         android:inputType = "textPassword"/>
   </android.support.design.widget.TextInputLayout>
   <Button
      android:id = "@+id/click"
      android:layout_width = "wrap_content"
      android:layout_height = "wrap_content"
      android:layout_gravity = "center"
      android:text = "Click"></Button>
</LinearLayout>

উপরের কোডে আমরা দুটি TextInputEditText এবং একটি বাটন দিয়েছি। আপনি যখন বোতামে ক্লিক করেন তখন এটি সম্পাদনা পাঠ থেকে ডেটা নেবে এবং টোস্টে দেখাবে।

ধাপ 3 − src/MainActivity.java

-এ নিম্নলিখিত কোড যোগ করুন
package com.example.andy.myapplication;

import android.graphics.Point;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.TextureView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
   EditText email,password;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      email = findViewById(R.id.email);
      password = findViewById(R.id.password);
      Button click = findViewById(R.id.click);
      click.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            if(!email.getText().toString().isEmpty()&&(!password.getText().toString().isEmpty())) {
               Toast.makeText(MainActivity.this, "you have entered email id " +                                     email.getText().toString() + "Password " + password.getText().toString(), Toast.LENGTH_LONG).show();
            } else {
               email.setError("Please Enter Email id");
               password.setError("Please Enter Pass word");
            }
         }
      });
   }
}

পদক্ষেপ 4৷ - build.gradle খুলুন এবং ডিজাইন সমর্থন লাইব্রেরি নির্ভরতা যোগ করুন।

apply plugin: 'com.android.application'
android {
   compileSdkVersion 28
   defaultConfig {
      applicationId "com.example.andy.myapplication"
      minSdkVersion 15
      targetSdkVersion 28
      compileSdkVersion 28
      versionCode 1
      versionName "1.0"
      testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
   }
   buildTypes {
      release {
         minifyEnabled false
         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      }
   }
}
dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'com.android.support:appcompat-v7:28.0.0'
   implementation 'com.android.support:design:28.0.0'
   implementation 'com.android.support.constraint:constraint-layout:1.1.3'
   testImplementation 'junit:junit:4.12'
   androidTestImplementation 'com.android.support.test:runner:1.0.2'
   androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

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

কিভাবে Android TextInputLayout বাস্তবায়ন করবেন

উপরের ফলাফলে প্রাথমিক স্ক্রীন রয়েছে। এখন কিছু ডেটা প্রবেশ করান এবং নীচের চিত্রের মতো বোতামে ক্লিক করুন -

কিভাবে Android TextInputLayout বাস্তবায়ন করবেন

এখন সমস্ত সম্পাদনা পাঠ্য ডেটা মুছে ফেলুন এবং বোতামে ক্লিক করুন। এটি নীচের হিসাবে দেখানো ফলাফল দেখাবে -

কিভাবে Android TextInputLayout বাস্তবায়ন করবেন


  1. অ্যান্ড্রয়েডে অ্যালার্ম ম্যানেজার কীভাবে প্রয়োগ করবেন?

  2. কিভাবে অ্যান্ড্রয়েড বোতাম শিট উইজেট বাস্তবায়ন করবেন?

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

  4. অ্যান্ড্রয়েডে রিসাইক্লারভিউ সহ অন্তহীন তালিকা কীভাবে বাস্তবায়ন করবেন?