header ads

Develop an application that uses GUI components, Font and Colors

 

Develop an application that uses GUI components, Font and Colors 



To develop a Simple Android Application that uses GUI components, Font and Colors.

Creating a New project:


Open Intellij Idea and then click on File -> New -> Project.




Select Android project




Then select the Empty Activity and click Next





Then type the Application name as “Exno1″. 
Then select language.
 Then select the Minimum SDK as shown below and click Next. 
 Finally click Finish. 
It will take some time to build and load the project. 





Designing layout for the Android Application: 

 Click on app -> res -> layout -> activity_main.xml. 
Now add text view and buttons. 



 

Code for ActivityMain.java



package com.example.exno1;
import android.graphics.Color;
//import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity
{
int ch=1;
float font=30;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t= (TextView) findViewById(R.id.textView);
Button b1= (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
t.setTextSize(font);
font = font + 5;
if (font == 50)
font = 30;
}
});
Button b2= (Button) findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (ch) {
case 1:
t.setTextColor(Color.RED);
break;
case 2:
t.setTextColor(Color.GREEN);
break;
case 3:
t.setTextColor(Color.BLUE);
break;
case 4:
t.setTextColor(Color.CYAN);
break;
case 5:
t.setTextColor(Color.YELLOW);
break;
case 6:
t.setTextColor(Color.MAGENTA);
break;
}
ch++;
if (ch == 7)
ch = 1;
}
});
}
}

Post a Comment

0 Comments