how to Set text, text color, image in Android using Java



activity_main.xml

<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="#004444" >
<TextView
  android:id="@+id/textView1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textSize="30sp"
  android:textColor="#000"
  android:text="saturday"
/>
<ImageView
  android:id="@+id/imageView1"
  android:layout_width="200dp"
  android:layout_height="200dp"
/>
</LinearLayout>



//put any image to res/drawable folder
MainActivity.java


import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView; 
import android.app.Activity;
import android.graphics.Color;

public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  //set layout
  setContentView(R.layout.activity_main);
  //initialize text view object
  TextView tv=(TextView)findViewById(R.id.textView1);
  //set text color
  tv.setTextColor(Color.RED);
  //set text
  tv.setText("This is my first app");
  //initialize image view object
  ImageView im=(ImageView)findViewById(R.id.imageView1);
  //set image resource
  im.setImageResource(R.drawable.myimage);
  }
}

Comments

Popular posts from this blog

how to fetch blob image gallery in php html sql

how to save image to pdf in android

How to create album view with fancybox slider view in html php complete code