Monday, September 14, 2015

Android TextView Example | Android Basic Tutorials| Android TextView Set value | Android TextView Set Color | Android TextView Set Font Size | Android TextView Demo Code

Simple TextView  Example code for beginners -


Your XML Layout-

<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:background="@android:color/white"
tools:context="com.androidhub4you.textview.MainActivity" >

<TextView
android:id="@+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="my blog"
android:textColor="@android:color/black"
android:textSize="20dp" />

</RelativeLayout>


Your Activity-
package com.androidhub4you.textview;

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

public class MainActivity extends Activity {
private TextView textViewName;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get the reference of textView from your layout
textViewName = (TextView) findViewById(R.id.textViewName);
/**
* you can override xml values inside your java code too
*/
// setting the text
textViewName.setText("androidhub4you.com");
// setting the color
textViewName.setTextColor(Color.GREEN);
// setting the font size
textViewName.setTextSize(25.0f);

}

}



Post your comment for more query .

Thank you!

1 comment :

  1. Hello, Manish thanks for your post, Can you help me how to send the TextView to gmail. thanks in advance

    ReplyDelete

Note: Only a member of this blog may post a comment.