Andriod Application
Andriod Application
ROLL NO # CB428849
REGISTRATION NO # 20NKK00577
(3499)
ASSIGNMENT NO # 01
TASK NO # 01 (BUTTON):-
MainActivity.kt
package com.example.application3
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
}
}
activity_main.xml
<?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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="154dp"
tools:layout_editor_absoluteY="426dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Main_activity2.kt
package com.example.application3
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
}
}
activity_main2.xml
<?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=".MainActivity2">
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2"
tools:layout_editor_absoluteX="174dp"
tools:layout_editor_absoluteY="311dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
TASK NO # 02 (DATATRANSFER):-
MainActivity.kt
package com.example.datatransfer
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
send_button = findViewById(R.id.send_button_id)
send_text = findViewById(R.id.send_text_id)
}
}
activity_main.xml
<?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"
android:background="#32a895"
tools:context=".MainActivity">
<EditText
android:id="@+id/send_text_id"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:hint="Input"
android:textSize="25dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/send_button_id"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#32a895"
android:text="Login"
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.635" />
</androidx.constraintlayout.widget.ConstraintLayout>
Second_activity.kt
package com.example.datatransfer
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
receiver_msg = findViewById(R.id.received_value_id)
// create the get Intent object
val intent = intent
// receive the value by getStringExtra() method and
// key must be same which is send by first activity
}
}
activity_second.xml
<?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:id="@+id/send_button_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Second_activity">
<TextView
android:id="@+id/received_value_id"
android:layout_width="300dp"
android:layout_height="50dp"
android:textSize="40sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/send_button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#32a895"
android:text="Login"
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.635" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity3.kt
package com.example.datatransfer
import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
receiver_msg = findViewById(R.id.received_value_id)
// create the get Intent object
val intent = intent
// receive the value by getStringExtra() method and
// key must be same which is send by first activity
val str = intent.getStringExtra("message_key")
}
}
activity_main3.xml
<?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=".MainActivity3">
<TextView
android:id="@+id/received_value_id"
android:layout_width="300dp"
android:layout_height="50dp"
android:textSize="40sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
TASK NO # 03 (FRAGMENT):-
MainActivity.java
package com.example.fragmenttest;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainerView,
NewsFragment.class, null)
.setReorderingAllowed(true)
.addToBackStack("name")
.commit();
}
});
FragmentManager fragmentManager =
getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainerView,
SportsFragment.class, null)
.setReorderingAllowed(true)
.addToBackStack("name")
.commit();
}
});
FragmentManager fragmentManager =
getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainerView,
ScienceFragment.class, null)
.setReorderingAllowed(true)
.addToBackStack("name")
.commit();
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
android:background="#B4C1E6"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="85dp"
android:background="#673AB7"
android:fontFamily="@font/zilla_slab_bold_italic"
android:paddingTop="20dp"
android:text="Fragment Test"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="34sp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/fragmentContainerView"
android:layout_width="match_parent"
android:layout_height="97dp"
android:orientation="horizontal"
android:paddingTop="10dp">
<Button
android:id="@+id/btnNews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#F44336"
android:text="News"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnScience"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#E91E63"
android:text="Science"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnSports"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#FFC107"
android:text="Sports"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnmovie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#00BCD4"
android:text="movie"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2809dp"
android:orientation="vertical"/>
</LinearLayout>
NewsFragment.java
package com.example.fragmenttest;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A simple {@link Fragment} subclass.
* Use the {@link NewsFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class NewsFragment extends Fragment {
public NewsFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment NewsFragment.
*/
// TODO: Rename and change types and number of parameters
public static NewsFragment newInstance(String param1, String param2) {
NewsFragment fragment = new NewsFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_news, container, false);
}
}
fragment_news.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:backgroundTint="#7C524F"
android:textAlignment="center"
tools:context="NewsFragment">
</FrameLayout>
ScienceFragment.java
package com.example.fragmenttest;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A simple {@link Fragment} subclass.
* Use the {@link ScienceFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class ScienceFragment extends Fragment {
public ScienceFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment ScienceFragment.
*/
// TODO: Rename and change types and number of parameters
public static ScienceFragment newInstance(String param1, String param2) {
ScienceFragment fragment = new ScienceFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_science, container, false);
}
}
fragment_science.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".ScienceFragment">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#218E9C"
android:fontFamily="@font/zilla_slab_bold_italic"
android:paddingTop="30dp"
android:text="Science Fragment"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="48sp"
android:textStyle="bold" />
</FrameLayout>
SportsFragment.java
package com.example.fragmenttest;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A simple {@link Fragment} subclass.
* Use the {@link SportsFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class SportsFragment extends Fragment {
public SportsFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment SportsFragment.
*/
// TODO: Rename and change types and number of parameters
public static SportsFragment newInstance(String param1, String param2) {
SportsFragment fragment = new SportsFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_sports, container, false);
}
}
fragment_sports.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".SportsFragment">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A3811C"
android:fontFamily="@font/zilla_slab_bold_italic"
android:paddingTop="30dp"
android:text="Sports Fragment"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="48sp"
android:textStyle="bold" />
</FrameLayout>
fragment_movie.java
package com.example.fragmenttest;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A simple {@link Fragment} subclass.
* Use the {@link fragment_movie#newInstance} factory method to
* create an instance of this fragment.
*/
public class fragment_movie extends Fragment {
public fragment_movie() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment ScienceFragment.
*/
// TODO: Rename and change types and number of parameters
public static fragment_movie newInstance(String param1, String param2) {
fragment_movie fragment = new fragment_movie();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_movie, container, false);
}
}
fragment_movie.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".ScienceFragment">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#218E9C"
android:fontFamily="@font/zilla_slab_bold_italic"
android:paddingTop="30dp"
android:text="Movie Fragment"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="48sp"
android:textStyle="bold" />
</FrameLayout>
MainActivity.kt
package com.example.toastdemo
import android.app.Activity
import android.content.Context
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.EditText
import android.widget.ListView
import android.widget.Toast
}
}
activity_main.xml
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="pink">#BF6081</color>
</resources>
custom_edittext.xml
<stroke
android:width="2dp"
android:color="@color/design_default_color_secondary_variant"/>
<corners
android:radius="30dp"/>
</shape>
activity_main.xml
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
app:cardCornerRadius="30dp"
app:cardElevation="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/custom_edittext"
android:orientation="vertical"
android:padding="24dp">
<TextView
android:id="@+id/loginText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="36sp"
android:textStyle="bold" />
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="40dp"
android:background="@drawable/custom_edittext"
android:drawableLeft="@drawable/ic_launcher_foreground"
android:drawablePadding="8dp"
android:hint="Username"
android:padding="8dp"
android:textColor="@color/black" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:background="@drawable/custom_edittext"
android:drawableLeft="@drawable/ic_launcher_foreground"
android:drawablePadding="8dp"
android:hint="Password"
android:inputType="textPassword"
android:padding="8dp"
android:textColor="@color/black" />
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="30dp"
android:backgroundTint="@color/pink"
android:text="Login"
android:textSize="18sp"
app:cornerRadius="20dp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
MainActivity.kt
package com.example.sofia6
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import com.example.sofia6.databinding.ActivityMainBinding
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.loginButton.setOnClickListener(View.OnClickListener {
if (binding.username.text.toString() == "user" &&
binding.password.text.toString() == "1234"){
Toast.makeText(this, "Login Successful!",
Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this, "Login Failed!",
Toast.LENGTH_SHORT).show()
}
})
}
}
}
===========THE END===========