B36 Exp8
B36 Exp8
PART A
A.1 Aim: To develop an application that uses GUI components, Fonts and colors.
A.2 Objectives: To introduce students with various tools like Android Studio, NS2, Wire-shark,
Cisco packet tracer, WAP supported browser etc.
A.3 Outcome:
After successful completion of this experiment students will be able to Develop an
application that uses GUI components, Fonts and colours A.4 Theory:
SOFTWARE:
• Android Studio
• Gradle
DESCRIPTION:
4 Enter the package name. package name must be two word separated by comma and click
finish
5 Go to package explorer in the left hand side and select our project.
6 Go to res folder and select layout. Double click the main.xml file 7 Now you can see the
Graphics layout window.
Source code:
CodeforActivity_main.xml:
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orient
ati on="vertical"
android:layout_width="match_parent"android:layout_height="mat ch_parent">
<TextViewandroid:id="@+id/textVi
ew"android:layout_width="match_
parent"
android:layout_height="wrap_content"
ndroid:layout_margin="30dp"android:
g ravity="center"android:text="Hello
World!"android:textSize="25sp"androi
d:textStyle="bold" />
<Button
android:id="@+id/button1"android:lay
out_width="match_parent"android:layo
ut_height="wrap_content"android:layou
t_margin="20dp"android:gravity="cent
er"android:text="Change font size"android:textSize="25sp"
/>
<Button
android:id="@+id/button2"android:lay
out_width="match_parent"android:lay o
ut_height="wrap_content"android:layo
u
t_margin="20dp"android:gravity="cent
er"android:text="Change color"android:textSize="25sp"
/>
CodeforMainActivity.java:
ackagecom.example.exno1;
importandroid.graphics.Col
or; import
android.support.v7.app.AppCompatActivity
; im port android.os.Bundle; import
android.view.View;import
android.widget.Button;impo rta
ndroid.widget.TextView;
publicclassMainActivityextendsAppCompatActivity
{
intch=1;floa
font=30;@
O verride
protectedvoidonCreate(BundlesavedInstanceState)
v)
{t.setTextSize(font); font
= font +
5;if (font
== 50)font
=30;
}
});
Button b2= (Button)
findViewById(R.id.button2);b2.setOnClickList
en er(newView.OnClickListener(){
@Override
{switch(ch){ case1:
t.setTextColor(Color.RED); break
case2:
t.setTextColor(Color.GREEN); break;
case3:
t.setTextColor(Color.BLUE)
; break;
case4:
t.setTextColor(Color.CYAN); break;
case5:
t.setTextColor(Color.YELLOW); break;
case6: t.setTextColor(Color.MAGENTA);
break;
}
}
});
}
}
ch++;
if ( ch == 7 ): ch
== 1;
Output:
PART B
(Students must submit the soft copy as per following segments within two hours of the
practical. The soft copy must be uploaded on the Blackboard or emailed to the concerned lab
in charge faculties at the end of the practical in case the there is no Black board access
available)
Grade:
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize views
TextView textView = findViewById(R.id.textView);
Button buttonSize = findViewById(R.id.button1);
Button buttonColor = findViewById(R.id.button2);
Button buttonTheme = findViewById(R.id.button3);
// Save preference
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("DarkMode", !isDark);
editor.apply();
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Exno8"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</application>
</manifest>
During the experiment, an Android application was developed using Android Studio to implement GUI
components, fonts, and colors. Various UI elements like TextView, Button, EditText, and ImageView
were added and customized using different fonts and colors. XML and Java/Kotlin code were used to
define the layout and functionality. The project successfully displayed a user interface with custom-styled
text, buttons, and background colors. Testing was conducted on an emulator and a physical device to
verify proper rendering of the UI components.
B.4 Conclusion:
The experiment provided hands-on experience in designing Android user interfaces with GUI
components, fonts, and colors. Students learned how to customize UI elements using XML properties
and Java/Kotlin code. This experiment helped them understand the importance of UI design in application
development and how to enhance the visual appeal of an Android application.
1. Install Android Studio, Java Development Kit (JDK), and Android SDK.
2. Configure Gradle dependencies.
1. Navigate to res/layout/activity_main.xml.
2. Add UI components like TextView, EditText, Button, and ImageView: