For Full video click on below link :-
https://youtu.be/RdKznpj3p30?si=41W4Dj0focRWbFln
Working with the activity_main.xml file.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@color/white">
<Button
android:id="@+id/openbtn"
android:layout_width="150dp"
android:layout_height="50dp"
android:backgroundTint="@color/black"
android:text="Open"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/txtadd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.219" />
</androidx.constraintlayout.widget.ConstraintLayout>
Working with the MainActivity.java file.
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file.
package com.example.bottom_dialog;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
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 {
Button btn;
TextView edt;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn= findViewById(R.id.openbtn);
edt = findViewById(R.id.txtadd);
Intent intent = getIntent();
String a = intent.getStringExtra("data");
edt.setText(a);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bottomsheet bottomsheet = new Bottomsheet();
bottomsheet.show(getSupportFragmentManager(),"TAG");
}
});
}
}
Create a new Layout file for out bottom sheet dialog.
Go to the row_add_item.xml file and refer to the following code. Below is the code for the row_add_item.xml file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/edittext2">
<View
android:layout_width="100dp"
android:layout_height="3dp"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:background="#232222"/>
<EditText
android:id="@+id/new_add_task_name"
android:layout_width="350dp"
android:layout_height="45dp"
android:background="@drawable/edit_text"
android:layout_marginTop="50dp"
android:layout_gravity="center_horizontal"
android:hint="Task Name"
android:textColorHint="#7733C1"
android:paddingStart="20dp"
tools:ignore="Autofill,HardcodedText,RtlSymmetry,TextFields" />
<EditText
android:id="@+id/new_add_task_des"
android:layout_width="350dp"
android:layout_height="45dp"
android:background="@drawable/edit_text"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:hint="Task Description"
android:textColorHint="#7733C1"
android:paddingStart="20dp"
tools:ignore="Autofill,HardcodedText,RtlSymmetry,TextFields" />
<Button
android:id="@+id/new_add_task_btn"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_marginTop="30dp"
android:layout_gravity="center_horizontal"
android:backgroundTint="#7733C1"
android:text="Done!!"
android:textColor="@color/white"
android:textSize="15sp"
tools:ignore="HardcodedText" />
<View
android:layout_width="100dp"
android:layout_height="3dp"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:background="#D5C3EC"/>
</LinearLayout>
Create a java class for bottom sheet dialog.
Go to the Bottomsheet.java file and refer to the following code. Below is the code for the Bottomsheet.java file.
package com.example.bottom_dialog;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
public class Bottomsheet extends BottomSheetDialogFragment {
public Bottomsheet() {
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.row_add_item,container,false);
Button btnadd=view.findViewById(R.id.new_add_task_btn);
EditText ed= view.findViewById(R.id.new_add_task_name);
btnadd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent =new Intent(getContext(), MainActivity.class);
intent.putExtra("data",ed.getText().toString());
startActivity(intent);
}
});
return view;
}
}
Comments
Post a Comment