Set text, text color, image in Android using Java

Set text, text color, image in Android using Java - Hello friends U-See, In the article you read in this time with the title Set text, text color, image in Android using Java, We have prepared this article well for you to read and take the information in it. Hopefully the contents of the post Artikel Android, Which we write you can understand. Okay, happy reading.

Title: Set text, text color, image in Android using Java
link : Set text, text color, image in Android using Java

Read also


Set text, text color, image in Android using Java

This is first simple android application and in this application, you all will learn how to set text, text color and image using Java. Create new project and open XML file and drag linear layout and take text view and image view from widgets and drop into linear layout. Give id textview1 to text view and imageview1 to image view. To change background color of layout use this code in XML:  android:background=”Color_Value” in linear layout tag. Android supports RGB, ARGB, RRGGBB, AARRGGBB color code. The code of android XML file is given below:


How to set text, text color, image in Android using Java

<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>

Now open your Java file and initialize text view and image view object.
To set text on text view use: textview_object.setText(“Any String”);
To set color on text use: textview_object.setTextColor(Color_name);
To set image first drop any image to any drawable folder and use this code to set image on image view: imageview_object.setImageResource(R.drawable.image_name);
The code of android Java file is given below:


package com.example.checkblogapp; //your package name

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);
  }
}

Now runs your project and if have any problem with the above code than please comment.



That's Set text, text color, image in Android using Java

That's an article Set text, text color, image in Android using Java This time, hopefully can benefit for you all. Well, see you in other article postings.

You are now reading the article Set text, text color, image in Android using Java With link address https://u-see1.blogspot.com/2017/06/set-text-text-color-image-in-android.html

Postingan terkait:

Belum ada tanggapan untuk "Set text, text color, image in Android using Java"

Post a Comment