0% found this document useful (0 votes)
12 views

Android Studio Lab2

The document discusses Android Studio layouts, activities lifecycle, Toasts, adding vector assets, and image assets. Relative layouts position views relative to other views. The activity lifecycle has 7 methods including onCreate(), onStart(), onResume(), onPause(), onStop(), onRestart(), and onDestroy(). Toasts provide simple feedback popups and automatically disappear. Vector assets allow importing scalable icons while image assets generate app icons from materials, images, and text.

Uploaded by

Azmeraw Zenaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Android Studio Lab2

The document discusses Android Studio layouts, activities lifecycle, Toasts, adding vector assets, and image assets. Relative layouts position views relative to other views. The activity lifecycle has 7 methods including onCreate(), onStart(), onResume(), onPause(), onStop(), onRestart(), and onDestroy(). Toasts provide simple feedback popups and automatically disappear. Vector assets allow importing scalable icons while image assets generate app icons from materials, images, and text.

Uploaded by

Azmeraw Zenaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Android Studio

Lab session
Layouts
● Relative Layouts
○ is a layout which arranges views/widgets/viewGroup according to the position
of other views/widgets/viewGroups i.e the new views are placed relative to the
already existing views
○ Most commonly used layout type
…cont’d
…cont’d
…cont’d
…cont’d
Android Activity Lifecycle – has 7 methods
● onCreate() – Called when the activity is first created
● onStart() – Called just after it’s creation or by restart method after onStop(). Here
Activity start becoming visible to user
● onResume() – Called when Activity is visible to user and user can interact with it
● onPause() – Called when Activity content is not visible because user resume previous
activity
● onStop() – Called when activity is not visible to user because some other activity takes
place of it
● onRestart() – Called when user comes on screen or resume the activity which was
stopped
● onDestroy – Called when Activity is not in background
onCreate()
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

}
onStart(), onRestart()
protected void onStart() {
super.onStart();
}

@Override
protected void onRestart() {
super.onRestart();
}
onPause(), onResume()
protected void onPause() {
super.onPause();

protected void onResume() {


super.onResume();
}
onStop(), onDestroy()
protected void onStop() {
super.onStop();

protected void onDestroy() {


super.onDestroy();
}
Toast Message
● A toast provides simple feedback about an operation in a small popup.
● It only fills the amount of space required for the message and the current activity
remains visible and interactive.
● Toasts automatically disappear after a timeout.
How to use a Toast
● Instantiate a Toast object (e.g Toast t1 ; )
● Use makeText() method with the following information:
○ Context
○ Text or String to be displayed
○ Time length
● Use show() to display the Toast message
● Example:
Context context=getApplicationContext();
CharSequence msg=“This is a Toast”;
int length=Toast.LENGTH.SHORT;
Toast t=Toast.makeText(context,msg,length).show();
Adding Vector Asset
● Vector Assets in Android Studio helps to add material icons and import Scalable
Vector Graphics (SVG) and Adobe Photoshop Document files into your project
as vector drawable resources.
● Image scalability is the major advantage of using the vector drawable.
● There are many formats of vector asset files:
○ Ai
○ Svg
○ Pdf
○ Eps
● Follow the following steps to implement vector assets
Implement Vector Asset
● Step 1: Right-click on drawable > New > Vector Asset
● After clicking on Vector Asset a new dialog box is opened that is shown below.
● Step 2: Click on Clip Art and Search for the Icons and click ok button
● Step 3: Change the color of the icon
● Step 4: Click Next Step
● 5: Now Click on Finish Button
● Step 6: Icon is created in the drawable folder
● Now you can refer it to in your xml file
Image Asset
● Helps you generate your own app icons from material icons, custom
images, and text strings.
● Follow the following step to include Image asset
● Step 1: First click on drawable > New > Image Asset.
● Step 2: Then a new dialog box will appear. Here click on the Image option.
● Step 3: Then search for the image you are looking for. And then upload it.
● Step 4: Now Click on Next.
● Step 5: Click on Finish.

You might also like