postheadericon Hello World in Android

Create “Hello World” application. That will display “Hello World” in the middle of the screen in the red color with white background.


File Name : HelloStudentsActivity.java


package bsr.example;

import android.app.Activity;
import android.os.Bundle;

public class HelloStudentsActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);      
        setContentView(R.layout.main);
    }
}

Layout : main.xml



<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:weightSum="1" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" android:background="@color/bgCol">

    <TextView android:layout_height="wrap_content" android:text="@string/hello" android:layout_width="fill_parent"></TextView>

    <TextView android:id="@+id/textView1" android:gravity="center_vertical|center_horizontal" android:freezesText="true" android:textColor="@color/fCol" android:textSize="12pt" android:layout_height="match_parent" android:layout_width="match_parent" android:layout_weight="0.35" android:text="Hello World"></TextView>

</LinearLayout>




Layout : string.xml


<?xml version="1.0" encoding="utf-8"?>
<resources>
   
    <string name="hello">Rupadiya Bipin, www.BipinRupadiya.blogspot.com</string><string name="app_name">SL-MC,  Exercise 1</string>
    <color name="fCol">#FF0000</color>
    <color name="bgCol">#FFFFFF</color>
</resources>


File Name : AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="bsr.example"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloStudentsActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>





Blog Archive

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.