We know that "Hello World" is the first program written in C language . Generally we started our programming skills with this program. So, here I write "Hello Android" programming in Android .One of the simplest program in Android.
3) Go to "res"->"values"->"string.xml" and edit this :
string.xml
MainActivity.java
package com.blogspot.satyaki.mukherjee.helloandroid;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
The result is :
or ,
You can edit the "TextView" also from java code:
package com.blogspot.satyaki.mukherjee.helloandroid;
import android.os.Bundle;
import android.widget.TextView;
import android.app.Activity;
public class MainActivity extends Activity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView=(TextView) findViewById(R.id.tv1);
textView.setText("Hello Android ? Hello Satyaki...");
textView.setTextSize(15);
textView.setTextColor(Color.RED);
}
}
The output is:
So, how to start Android programming in Eclipse ? Don't worry . It's very simple. Follow the instructions :
1) Go to File -> New -> Project -> Android -> Android Application Project -> Next
After that give the project name, package name in this manner :
then press the "Next" button, and follow the steps one by one.
2) Go to "res"->"layout"->"main.xml"(xml name depend upon user choice) and write this :
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="30sp"
android:textColor="#078FCE"
android:text="@string/hello_android" />
</RelativeLayout>
3) Go to "res"->"values"->"string.xml" and edit this :
string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Hello Android</string>
<string name="action_settings">Settings</string>
<string name="hello_android">Hello Android!</string>
</resources>
4) Go to "src"->"package name(here com.blogspot.satyaki.mukherjee.helloandroid)"->"MainActivity.java"(the java file name is also depend upon user choice) and write this java code:
MainActivity.java
package com.blogspot.satyaki.mukherjee.helloandroid;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
The result is :
or ,
You can edit the "TextView" also from java code:
package com.blogspot.satyaki.mukherjee.helloandroid;
import android.os.Bundle;
import android.widget.TextView;
import android.app.Activity;
public class MainActivity extends Activity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView=(TextView) findViewById(R.id.tv1);
textView.setText("Hello Android ? Hello Satyaki...");
textView.setTextSize(15);
textView.setTextColor(Color.RED);
}
}
The output is:
If you have any query regarding this , then you can freely contact with me.
Thanks.
No comments:
Post a Comment