0% found this document useful (0 votes)
7 views29 pages

Android Programming Practical Tasks

Ransom

Uploaded by

Gaurav Daware
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views29 pages

Android Programming Practical Tasks

Ransom

Uploaded by

Gaurav Daware
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Android Programming

Name: ____________________________

ID: _______________________________

Division: D03

Branch: Computer Engineering

Android Practicals List


No. Practical Date Signature
1 Installation of Android Studio
2 Write a program using Button, TextView,
EditText, Toast, and ToggleButton
3 Create a Registration Page with Button,
TextView, EditText, CheckBox, RadioButton,
RadioGroup, and Toast
4 Write a program to implement
AutoCompleteTextView
5 Write a program to implement ImageButton
6 Write a program to implement AlertDialog
with Positive and Negative buttons
7 Write a program to implement AlertDialog
with single choice items
8 Write a program to implement Spinner
9 Write a program to implement Spinner using
[Link]
10 Write a program to implement ListView
using [Link]
11 Write a program to implement Custom
ListView
12 Write a program to implement Dynamic
RadioButton
13 Write a program to implement RatingBar
14 Write a program to implement Android
WebView
15 Write a program to implement SeekBar
16 Write a program to implement DatePicker
17 Write a program to implement TimePicker
18 Write a program to implement AnalogClock
and DigitalClock
19 Write a program to implement ProgressBar
20 Write a program to implement ScrollView
21 Write a program to implement Toolbar or
ActionBar
22 Write a program to implement Options Menu
with image icons
23 Write a program to implement Context Menu
24 Write a program to implement Popup Menu
25 Write a program to pass data from one
Activity to another Activity

Task 2: Button, TextView, EditText, Toast, ToggleButton


[Link]
---------------------------------
package [Link];

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

public class Task2Activity extends AppCompatActivity {


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

EditText et = findViewById([Link]);
TextView tv = findViewById([Link]);
Button btn = findViewById([Link]);
ToggleButton toggle = findViewById([Link]);

[Link](v -> {
String text = [Link]().toString();
[Link](text);
[Link](this, "Button clicked: " + ([Link]() ? "ON" : "OFF"),
Toast.LENGTH_SHORT).show();
});
}
}

activity_task2.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="16dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">

<EditText android:id="@+id/et" android:hint="Enter text"


android:layout_width="match_parent" android:layout_height="wrap_content"/>
<Button android:id="@+id/btn" android:text="Set Text & Toast"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ToggleButton android:id="@+id/toggle" android:textOn="ON" android:textOff="OFF"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/tv" android:text="Result" android:textSize="18sp"
android:layout_marginTop="16dp" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

Task 3: Registration Page (Button, TextView, EditText, CheckBox,


RadioButton, RadioGroup, Toast)
[Link]
---------------------------------
package [Link];

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

public class Task3Activity extends AppCompatActivity {


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

EditText name = findViewById([Link]);


EditText email = findViewById([Link]);
CheckBox terms = findViewById([Link]);
RadioGroup rg = findViewById([Link]);
Button submit = findViewById([Link]);

[Link](v -> {
String n = [Link]().toString().trim();
String e = [Link]().toString().trim();
int sel = [Link]();
String gender = sel == -1 ? "Not selected" :
((RadioButton)findViewById(sel)).getText().toString();
if ([Link]() || [Link]()) {
[Link](this, "Please fill name and email", Toast.LENGTH_SHORT).show();
return;
}
if (![Link]()) {
[Link](this, "Accept terms first", Toast.LENGTH_SHORT).show();
return;
}
[Link](this, "Name: " + n + "
Email: " + e + "
Gender: " + gender, Toast.LENGTH_LONG).show();
});
}
}

activity_task3.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="[Link]
android:layout_width="match_parent" android:layout_height="match_parent" >
<LinearLayout android:padding="16dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="wrap_content">

<TextView android:text="Registration" android:textSize="20sp"


android:layout_marginBottom="8dp" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText android:id="@+id/name" android:hint="Name"
android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:id="@+id/email" android:inputType="textEmailAddress"
android:hint="Email" android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RadioGroup android:id="@+id/rg" android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<RadioButton android:id="@+id/male" android:text="Male"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<RadioButton android:id="@+id/female" android:text="Female"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</RadioGroup>
<CheckBox android:id="@+id/terms" android:text="I accept terms"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<Button android:id="@+id/submit" android:text="Register"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>

Task 4: AutoCompleteTextView
[Link]
---------------------------------
package [Link];

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

public class Task4Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task4);
AutoCompleteTextView auto = findViewById([Link]);
String[] countries = {"India","Indonesia","Canada","China","USA","United Kingdom"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
[Link].simple_dropdown_item_1line, countries);
[Link](adapter);
[Link](1);
}
}

activity_task4.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="16dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<AutoCompleteTextView android:id="@+id/auto" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="Start typing country"/>
</LinearLayout>

Task 5: ImageButton
[Link]
---------------------------------
package [Link];

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

public class Task5Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task5);
ImageButton ib = findViewById([Link]);
[Link](v -> [Link](this, "ImageButton clicked",
Toast.LENGTH_SHORT).show());
}
}

activity_task5.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="[Link]
android:padding="16dp" android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageButton android:id="@+id/imageButton"
android:src="@android:drawable/ic_menu_camera" android:layout_gravity="center"
android:contentDescription="camera" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
Task 6: AlertDialog with Positive and Negative buttons
[Link]
---------------------------------
package [Link];

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

public class Task6Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task6);
Button b = findViewById([Link]);
[Link](v -> {
new [Link](this)
.setTitle("Confirm")
.setMessage("Do you want to continue?")
.setPositiveButton("Yes", (d, w) -> [Link]())
.setNegativeButton("No", (d, w) -> [Link]())
.show();
});
}
}

activity_task6.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:gravity="center" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button android:id="@+id/show" android:text="Show Dialog"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
Task 7: AlertDialog with single choice items
[Link]
---------------------------------
package [Link];

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

public class Task7Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task7);
Button btn = findViewById([Link]);
[Link](v -> {
String[] items = {"Red","Green","Blue"};
new [Link](this)
.setTitle("Pick a color")
.setSingleChoiceItems(items, -1, (dialog, which) -> {
[Link](this, "Selected: " + items[which], Toast.LENGTH_SHORT).show();
[Link]();
})
.show();
});
}
}
activity_task7.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="[Link]
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="16dp">
<Button android:id="@+id/btn" android:text="Choose Color"
android:layout_gravity="center" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>

Task 8: Spinner
[Link]
---------------------------------
package [Link];

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

public class Task8Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task8);
Spinner sp = findViewById([Link]);
String[] data = {"One","Two","Three"};
ArrayAdapter<String> ad = new ArrayAdapter<>(this,
[Link].simple_spinner_item, data);
[Link]([Link].simple_spinner_dropdown_item);
[Link](ad);
}
}

activity_task8.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="16dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<Spinner android:id="@+id/spinner" android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Task 9: Spinner using [Link]
[Link] (add under res/values/[Link])
---------------------------------
<resources>
<string name="app_name">MyApp</string>
<string-array name="numbers">
<item>One</item>
<item>Two</item>
<item>Three</item>
</string-array>
</resources>

[Link]
---------------------------------
package [Link];

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

public class Task9Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task9);
Spinner sp = findViewById([Link]);
ArrayAdapter<CharSequence> adapter = [Link](this,
[Link], [Link].simple_spinner_item);

[Link]([Link].simple_spinner_dropdown_item);
[Link](adapter);
}
}

activity_task9.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="16dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<Spinner android:id="@+id/spinner" android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

Task 10: ListView using [Link]


[Link] (add under res/values/[Link])
---------------------------------
<resources>
<string-array name="friends">
<item>Alice</item>
<item>Bob</item>
<item>Charlie</item>
</string-array>
</resources>

[Link]
---------------------------------
package [Link];

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

public class Task10Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task10);
ListView lv = findViewById([Link]);
ArrayAdapter<CharSequence> adapter = [Link](this,
[Link], [Link].simple_list_item_1);
[Link](adapter);
}
}

activity_task10.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="16dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<ListView android:id="@+id/listView" android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

Task 11: Custom ListView


row_item.xml (res/layout/row_item.xml)
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:orientation="horizontal" android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView android:id="@+id/icon" android:layout_width="40dp"
android:layout_height="40dp"
android:src="@android:drawable/ic_menu_gallery"/>
<TextView android:id="@+id/title" android:textSize="16sp"
android:layout_marginStart="8dp" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

[Link]
---------------------------------
package [Link];

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

public class Task11Activity extends AppCompatActivity {


String[] items = {"Apple","Banana","Cherry"};

@Override
protected void onCreate(Bundle s) {
[Link](s);
setContentView([Link].activity_task11);
ListView lv = findViewById([Link]);
[Link](new CustomAdapter());
}

class CustomAdapter extends BaseAdapter {


@Override public int getCount() { return [Link]; }
@Override public Object getItem(int i) { return items[i]; }
@Override public long getItemId(int i) { return i; }
@Override public View getView(int pos, View convertView, ViewGroup
parent) {
if (convertView == null) {
convertView =
[Link]([Link]).inflate([Link].row_item, parent,
false);
}
TextView tv = [Link]([Link]);
ImageView iv = [Link]([Link]);
[Link](items[pos]);
return convertView;
}
}
}

activity_task11.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:padding="8dp" android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

Task 12: Dynamic RadioButton


[Link]
---------------------------------
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class Task12Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task12);
RadioGroup rg = findViewById([Link]);
String[] options = {"Option A","Option B","Option C"};
for (int i = 0; i < [Link]; i++) {
RadioButton rb = new RadioButton(this);
[Link](options[i]);
[Link](100 + i);
[Link](rb, new
[Link]([Link].WRAP_CONTENT,
[Link].WRAP_CONTENT));
}
[Link]((group, checkedId) -> {
RadioButton checked = findViewById(checkedId);
if (checked != null) [Link](this, "Selected: " + [Link](),
Toast.LENGTH_SHORT).show();
});
}
}

activity_task12.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="16dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<RadioGroup android:id="@+id/rg" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
Task 13: RatingBar
[Link]
---------------------------------
package [Link];

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

public class Task13Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task13);
RatingBar rb = findViewById([Link]);
[Link]((ratingBar, rating, fromUser) ->
[Link](this, "Rating: " + rating, Toast.LENGTH_SHORT).show());
}
}

activity_task13.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="16dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<RatingBar android:id="@+id/ratingBar" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:numStars="5" android:stepSize="1.0"/>
</LinearLayout>

Task 14: Android WebView


[Link]
---------------------------------
package [Link];

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

public class Task14Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task14);
WebView web = findViewById([Link]);
[Link](new WebViewClient());
WebSettings ws = [Link]();
[Link](true);
[Link]("[Link]
}
}

activity_task14.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="0dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<WebView android:id="@+id/webView" android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

Task 15: SeekBar


[Link]
---------------------------------
package [Link];

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

public class Task15Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task15);
SeekBar sb = findViewById([Link]);
TextView tv = findViewById([Link]);
[Link](new [Link]() {
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean
fromUser) { [Link]("Value: " + progress); }
@Override public void onStartTrackingTouch(SeekBar seekBar) {}
@Override public void onStopTrackingTouch(SeekBar seekBar) {}
});
}
}

activity_task15.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="16dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<SeekBar android:id="@+id/seekBar" android:layout_width="match_parent"
android:layout_height="wrap_content" android:max="100"/>
<TextView android:id="@+id/value" android:text="Value: 0"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp"/>
</LinearLayout>
Task 16: DatePicker
[Link]
---------------------------------
package [Link];

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

public class Task16Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task16);
Button btn = findViewById([Link]);
TextView tv = findViewById([Link]);
[Link](v -> {
Calendar c = [Link]();
int y = [Link]([Link]);
int m = [Link]([Link]);
int d = [Link](Calendar.DAY_OF_MONTH);
new DatePickerDialog(this, (view, year, month, dayOfMonth) -> {
[Link](dayOfMonth + "/" + (month+1) + "/" + year);
}, y, m, d).show();
});
}
}

activity_task16.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="16dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<Button android:id="@+id/btnDate" android:text="Pick Date"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/tvDate" android:text="Selected date"
android:layout_marginTop="8dp" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

Task 17: TimePicker


[Link]
---------------------------------
package [Link];

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

public class Task17Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task17);
Button btn = findViewById([Link]);
TextView tv = findViewById([Link]);
[Link](v -> {
Calendar c = [Link]();
int h = [Link](Calendar.HOUR_OF_DAY);
int m = [Link]([Link]);
new TimePickerDialog(this, (view, hourOfDay, minute) -> {
[Link]([Link]("%02d:%02d", hourOfDay, minute));
}, h, m, true).show();
});
}
}

activity_task17.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="16dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<Button android:id="@+id/btnTime" android:text="Pick Time"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/tvTime" android:text="Selected time"
android:layout_marginTop="8dp" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

Task 18: AnalogClock and DigitalClock


activity_task18.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="16dp" android:orientation="vertical" android:gravity="center"
android:layout_width="match_parent" android:layout_height="match_parent">
<AnalogClock android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:text="" android:layout_marginTop="8dp"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextClock android:layout_width="wrap_content" android:layout_height="wrap_content"
android:format12Hour="hh:mm:ss a" android:layout_marginTop="8dp"/>
</LinearLayout>

[Link]
---------------------------------
package [Link];

import [Link];
import [Link];

public class Task18Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task18);
}
}
Task 19: ProgressBar
[Link]
---------------------------------
package [Link];

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

public class Task19Activity extends AppCompatActivity {


ProgressBar pb;
Handler handler = new Handler();
int progress = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task19);
pb = findViewById([Link]);
Button start = findViewById([Link]);
[Link](v -> {
[Link]([Link]);
progress = 0;
[Link](progress);
[Link](new Runnable() {
@Override public void run() {
progress += 10;
[Link](progress);
if (progress < 100) [Link](this, 500);
}
}, 500);
});
}
}

activity_task19.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:padding="16dp" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<ProgressBar android:id="@+id/progressBar"
style="@android:style/[Link]"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:visibility="gone" android:max="100"/>
<Button android:id="@+id/startBtn" android:text="Start"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp"/>
</LinearLayout>

Task 20: ScrollView


activity_task20.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="[Link]
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:orientation="vertical" android:padding="16dp"
android:layout_width="match_parent" android:layout_height="wrap_content">
<!-- Add many TextViews to demo scrolling -->
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Line 1"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Line 2"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Line 3"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Line 4"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Line 5"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Line 6"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Line 7"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Line 8"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Line 9"/>
</LinearLayout>
</ScrollView>

Task 21: Toolbar or ActionBar


activity_task21.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
android:layout_width="match_parent" android:layout_height="match_parent">
<[Link]
android:layout_width="match_parent" android:layout_height="wrap_content">
<[Link] android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:title="My Toolbar"/>
</[Link]>

<LinearLayout android:orientation="vertical" android:layout_width="match_parent"


android:layout_height="match_parent" android:padding="16dp">
<TextView android:text="Content goes here" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</[Link]>

[Link]
---------------------------------
package [Link];

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

public class Task21Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_task21);
Toolbar toolbar = findViewById([Link]);
setSupportActionBar(toolbar);
}
}

You might also like