How to Create a Date Picker in ActionBar in Calendar App.

Android Studio में Calendar App के लिए Hindi भाषा में Date Picker कैसे बनाएं।

इस एप्लिकेशन में, हम एक्शन बार में डेट पिकर बनाएंगे, इसलिए यदि आप कैलेंडर ऐप में वास्तविक तारीख दिखाना चाहते हैं, तो आपको इस ब्लॉग का अनुसरण करना होगा। जिससे आपको एक नए तरह के डिजाइन के बारे में बताया जा रहा है।

In this application, we will make a date picker in the action bar so if you want to show the actual date in the calendar app, you must follow this blog. By which you are being told about a new kind of design.

इसके साथ ही हम यह भी जानेंगे कि जिस तारीख को ऐप खोला जाएगा, उसमें वही तारीख दिखाई देगी।

Along with this, we will also learn that the date on which the app will be opened will show the same date.

अब HomeActivity फाइल में कोड को कॉपी पेस्ट करना है

सबसे पहले, हम DrawerLayout बनाएंगे और उसके कोड को कॉपी करेंगे।

First of all, we will create DrawerLayout and copy its code.

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/purple_200"
    android:fitsSystemWindows="true"
    tools:context=".HomeActivity">

</androidx.drawerlayout.widget.DrawerLayout>

अब हम इसके अंदर Constraint Layout create करेंगे।

Now we will create Constraint Layout inside it.

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</androidx.constraintlayout.widget.ConstraintLayout>

अब हम Constraint Layout के अंदर एक AppBar Layout बनाएंगे।

Now we will create an AppBar Layout inside the Constraint Layout.

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

</com.google.android.material.appbar.AppBarLayout>

अब हम AppBarLayout के अंदर एक ToolBar Layout बनाएंगे।

Now we will create a ToolBar Layout inside the AppBarLayout.

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

</androidx.appcompat.widget.Toolbar>

अब हम ToolBar के अंदर एक Constraint Layout बनाएँगे।

Now we will create a Constraint Layout inside the ToolBar.

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="2dp"
    android:background="@drawable/main_bg"
    android:paddingStart="8dp"
    android:paddingTop="2dp"
    android:paddingEnd="8dp"
    android:paddingBottom="2dp">
    

</androidx.constraintlayout.widget.ConstraintLayout>

इस Constraint Layout में बैकग्राउंड को अलग से डिजाईन किया जाता है जिसका नाम है main_bg.xml Layout तो सबसे पहले हम वो डिजाईन बनायेंगे उसके बाद ही आगे बढेंगे.

In this Constraint Layout, the background is designed separately, whose name is main_bg.xml layout, so first of all, we will make that design and only then proceed.

main_bf.xml लेआउट का कोड नीचे दिया गया है।

The code of the main_bf.xml layout is given below.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners android:radius="4dp" />
    <stroke
        android:width="2dp"
        android:color="@color/white" />

</shape>

अब Constraint Layout के अंदर एक TextView डिज़ाइन करें और बनाएं जो आपके ऐप का नाम दिखाएगा।

Now design and create a TextView inside the Constraint Layout which will show the name of your app.

<TextView
    android:id="@+id/headerTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:shadowColor="@color/white"
    android:shadowDx="1.5"
    android:shadowDy="1.3"
    android:shadowRadius="1.6"
    android:text="ठाकुर प्रसाद कैलेंडर - 2023"
    android:textColor="@color/white"
    android:textSize="24sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0" />

अब हम TextView के नीचे एक LinearLayout बनाएंगे जहां हम तारीख को डिजाइन करेंगे जो दिखाई देगी, इसके लिए सभी TextView लेआउट क्षैतिज दृश्य में होंगे।

Now we will create a LinearLayout below the TextView where we will design the date which will appear, for this all TextView Layout will be in Horizontal view.

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingTop="2dp"
    android:paddingBottom="2dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/headerTextView">

</LinearLayout>

दिनांक को टेक्स्टव्यू लेआउट से डिज़ाइन किया गया है।

The date is designed from TextView Layout.

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="4dp"
    android:gravity="center"
    android:text="आज की तारीख़"
    android:textColor="@android:color/holo_orange_dark"
    android:textSize="16sp"
    android:textStyle="bold" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text=":"
    android:textColor="@color/white"
    android:textSize="16sp"
    android:textStyle="bold" />
<TextView
    android:id="@+id/viewDate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="4dp"
    android:gravity="center"
    android:text="01 Jan 2023"
    android:textColor="@android:color/holo_green_light"
    android:textSize="16sp"
    android:textStyle="bold" />

अब काम है Java Code का तो बस आप में कुछ लाइन जोड़ने से हमारा प्रोजेक्ट पूरा हो जायेगा

Now the work of Java Code is there, then by adding just a few lines to you, our project will be complete.

Calendar calendar = Calendar.getInstance();
String currentDate = DateFormat.getDateInstance().format(calendar.getTime());

TextView textViewDate = findViewById(R.id.viewDate);
textViewDate.setText(currentDate);

Leave a Reply

Your email address will not be published. Required fields are marked *

× Chat Now