Im very new to this android development.I just started to create a hello world application.
I tried to set a background image and it is working fine.When i tried to add a text on the image it is not working.
I tried in the way below.Can anyone please help me where im going wrong.
in
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/andriod"
android:layout_gravity="center_vertical"
android:gravity="center_vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
HelloActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
//import android.widget.ImageView;
public class HelloActivity extends Activity {
// /** Called when the activity is first created. */
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
// }
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("This is the first andorid app");
setContentView(R.layout.main);
}
}
When running it is showing the background image but “This is the first andorid app” is not showing.
Hoping for your help
You must select the TextView in your layout file with its unique ID and then set it properties. But in ur code, u just create a text view with the text and not place it into the view.