/*Create “Hello World” application that will display “Hello World” in the middle of the screen in emulator. Also display “Hello World” in the middle of the screen in the android phone.*/
File Name: 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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView android:text="Hello World"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hello"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textSize="50sp" />
</RelativeLayout>
File Name: MainActivity.java
package com.fuzzycode.helloworld;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super .onOptionsItemSelected(item);
}
}
ouput:
No comments:
Post a Comment