Name: Shubhasmita S Sahu
Class: TYIT
Seat No.: 2013263
Practical No: 02
Programming Resources
Android Resources: (Color, Theme, String, Drawable, Dimension, Image).
Drawable:
A drawable folder is nothing but a resource directory in Android studio source code of
your project. 2. This folder contains all versions of images say mdpi, hdpi, xhdpi, xxhdpi etc.
1. Right click on drawable folder
2. Copy the image if you want to create image drawable
3. Paste that image file inside the drawable folder
ADVANCED MOBILE PROGRAMMING
Name: Shubhasmita S Sahu
Class: TYIT
Seat No.: 2013263
ADVANCED MOBILE PROGRAMMING
Name: Shubhasmita S Sahu
Class: TYIT
Seat No.: 2013263
layout :
A layout defines the structure for a user interface in your app, such as in an activity. All
elements in the layout are built using a hierarchy of View and ViewGroup objects. A View
usually draws something the user can see and interact with.XML layout files that describe the
views and layouts for each activity
Mipmap:
The mipmap folders are for placing your app/launcher icons (which are shown on the
homescreen) in only. Any other drawable assets you use should be placed in the relevant
drawable folders as before.
ADVANCED MOBILE PROGRAMMING
Name: Shubhasmita S Sahu
Class: TYIT
Seat No.: 2013263
Values:
The res/values folder is used to store the values for the resources that are used in many
Android projects to include features of color, styles, dimensions etc. Below explained are
few basic files, contained in the res/values folder: colors. xml: The colors.
Color:
The colors.xml is an XML file which is used to store the colors for the resources. An
Android project contains 3 essential colours namely:
• colorPrimary
• colorPrimaryDark
• colorAccent
Color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>
ADVANCED MOBILE PROGRAMMING
Name: Shubhasmita S Sahu
Class: TYIT
Seat No.: 2013263
Theme
Style
Styles in Android allow you to define the look and feel, for example colors and fonts, of Android
components in XML resource files. The name of the XML file is arbitrary,
but it must use the .xml extension. You can define multiple styles per file using <style> tag but
each style will have its name that uniquely identifies the style.
Style.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!--
Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item
name="colorAccent">@color/colorAccent</item>
</style>
</resources>
ADVANCED MOBILE PROGRAMMING
Name: Shubhasmita S Sahu
Class: TYIT
Seat No.: 2013263
String:
Basic function of the strings.xml is to define the strings in one file so that it is easy to use same string in
different positions in the android project plus it makes the project looks less messy.
We can also define an array in this file as well.
String.xml:
<resources>
<string name="app_name">My Application</string>
<String name="cources"/>
<item name="FYIT" type="string"/>
<item name="SYIT" type="string"/>
<item name="TYIT" type="string"/>
</resources>
Dimension:
A dimension value defined in XML. A dimension is specified with a number followed by a unit of
measure. For example: 10px, 2in, 5sp. The following units of measure are supported by Android: dp.
Image:
ImageView class is used to display any kind of image resource in the android application either it can
be android. graphics. Bitmap or android. graphics. ... Application of ImageView is also in applying tints
to an image in order to reuse a drawable resource and create overlays on background images
ADVANCED MOBILE PROGRAMMING
Name: Shubhasmita S Sahu
Class: TYIT
Seat No.: 2013263
Program Code:
ImageView
Main_Activity.java:
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
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="@drawable/hope"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello!"
android:textColor="#CF1C1C"
android:textSize="36sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.553"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.127" />
</androidx.constraintlayout.widget.ConstraintLayout>
Output:
ADVANCED MOBILE PROGRAMMING
Name: Shubhasmita S Sahu
Class: TYIT
Seat No.: 2013263
ADVANCED MOBILE PROGRAMMING