Ex. No: 1 Date: GUI Components, Font and Colours Aim
Ex. No: 1 Date: GUI Components, Font and Colours Aim
Ex. No: 1 Date: GUI Components, Font and Colours Aim
No : 1
GUI Components, Font and Colours
Date :
AIM :
Develop an application that uses GUI components, Font and Colours
Step 3 : In the displayed window type Application name as Ex.No 1 , and click Next
4 times.
Step 4 : In the Last window type Activity Name and Layout Name, and press Finish
Step 7 : a. Using Graphical layout drag and drop the following Components
OR
Step 7 : b. Using XML code Choose activity_main.xml,
type the below Code
activity_main.xml
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20sp"
android:gravity="center"
android:text="@string/msg"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/fontSize"
android:textSize="20sp" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/fontColor"
android:textSize="20sp" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/changeFont"
android:textSize="20sp" />
</LinearLayout>
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t1 = (TextView)
findViewById(R.id.textView1);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
t1.setText("FONT SIZE");
t1.setTextSize(font);
font = font + 5;
if (font == 50)
font = 20;
}
});
b2 = (Button) findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
t1.setText("FONT COLOR");
switch (count) {
case 1:
t1.setTextColor(Color.parseColor("#7f00ff"));
break;
case 2:
t1.setTextColor(Color.parseColor("#00FF00"));
break;
case 3:
t1.setTextColor(Color.parseColor("#FF0000"));
break;
case 4:
t1.setTextColor(Color.parseColor("#0000FF"));
break;
}
count++;
if (count == 5)
count = 1;
}
});
b3 = (Button) findViewById(R.id.button3);
b3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
t1.setText("FONT");
switch (count) {
case 1:
t1.setTypeface(Typeface.DEFAULT,
Typeface.ITALIC);
break;
case 2:
t1.setTypeface(Typeface.MONOSPACE,
Typeface.NORMAL);
break;
case 3:
t1.setTypeface(Typeface.SANS_SERIF,
Typeface.BOLD);
break;
case 4:
t1.setTypeface(Typeface.SERIF,
Typeface.BOLD_ITALIC);
break;
}
count++;
if (count == 5)
count = 1;
}
});
}
}
Step 9 : Save All and Run it as Android Application (Ctrl + F11) .
OUTPUT:
RESULT:
Thus the above android application has been run successfully.