0% found this document useful (0 votes)
9 views6 pages

Exp 4

The document contains Android application code for two different activities that allow users to input text and display it. The first activity takes user input and displays it in a TextView, while the second activity greets the user by name. Both activities utilize modern Android features like Edge-to-Edge support and window insets for proper layout management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Exp 4

The document contains Android application code for two different activities that allow users to input text and display it. The first activity takes user input and displays it in a TextView, while the second activity greets the user by name. Both activities utilize modern Android features like Edge-to-Edge support and window insets for proper layout management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

package [Link].

helloworld;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);

[Link](findViewById([Link]), (v, insets) -> {


Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

EditText editText = findViewById([Link]);


TextView textView = findViewById([Link]);
Button button = findViewById([Link]);

[Link](v -> {
String inputText = [Link]().toString().trim();

if ([Link]()) {
[Link](this, "Please enter some text", Toast.LENGTH_SHORT).show();
} else {
[Link](inputText);
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:gravity="top"
tools:context=".MainActivity">

<EditText
android:id="@+id/editTextInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text here"
android:inputType="text"
android:importantForAutofill="no" />
<Button
android:id="@+id/buttonShow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Text"
android:layout_marginTop="12dp" />

<TextView
android:id="@+id/textViewOutput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Output will appear here"
android:textSize="18sp"
android:textColor="@android:color/black"
android:layout_marginTop="16dp" />

<!-- Spacer to push footer down -->


<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

<!-- Footer -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bhatia Nikhil"
android:textSize="14sp"

android:textColor="@android:color/darker_gray"
android:layout_gravity="center_horizontal" />

</LinearLayout>
4_1:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:background="#23aab4"
tools:context=".MainActivity">

<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter name"
android:inputType="textPersonName"
android:importantForAutofill="no" />

<Button
android:id="@+id/buttonGreet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Greet"
android:layout_marginTop="12dp"
android:backgroundTint="#0D47A1"
android:textColor="@android:color/white" />

<TextView
android:id="@+id/textViewGreeting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Greeting"
android:textSize="18sp"
android:layout_marginTop="16dp"
android:textColor="@android:color/black" />

<!-- Simple Footer -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bhatia Nikhil student"
android:layout_marginTop="24dp"
android:textColor="@android:color/white" />

</LinearLayout>

package [Link].exp4_1;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);

[Link](findViewById([Link]), (v, insets) -> {


Insets systemBars = [Link]([Link]());
[Link]([Link], [Link], [Link], [Link]);
return insets;
});

EditText editText = findViewById([Link]);


TextView textView =
findViewById([Link]);
Button button =
findViewById([Link]);

[Link](v -> {
String name =
[Link]().toString().trim();

if ([Link]()) {
[Link](this, "Please enter your
name", Toast.LENGTH_SHORT).show();
} else {
[Link]("Hello, " + name + "!");
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">

<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter name"
android:inputType="textPersonName"
android:importantForAutofill="no" />

<Button
android:id="@+id/buttonGreet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Greet"
android:layout_marginTop="12dp"
android:backgroundTint="#1E88E5"
android:textColor="@android:color/white" />

<!-- Greeting Output (Styled) -->


<TextView
android:id="@+id/textViewGreeting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Greeting"
android:textSize="34sp"
android:textColor="#1E88E5"
android:textStyle="bold"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal" />

<!-- Spacer -->


<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

<!-- Simple Footer -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bhatia Nikhil student"
android:textColor="@android:color/darker_gray"
android:layout_gravity="center_horizontal" />

</LinearLayout>

package [Link].exp4_2;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
});

EditText editText = findViewById([Link]);


TextView textView = findViewById([Link]);
Button button = findViewById([Link]);

[Link](v -> {
String name = [Link]().toString().trim();

if ([Link]()) {
[Link](this,
"Please enter your name",
Toast.LENGTH_SHORT).show();
} else {

[Link]("Hello, " +
name + "!");
}
});
}
}

You might also like