Tuesday 6 October 2015

Android Simple TextView example tutorial

Android TextView tag is applied to display user generated text on android applications. TextView tag is the most common generic tag to develop static android apps. TextView tag also gives the facility to change the text bye application developer. TextView dose not function single there are some of it's attributes to provide TextView ground support.

Textview tag is already written in blank activity application therefore each & every time you have create a new application project using Android Studio or Eclipse the textView tag is already written there in activity_main.xml file.

Android Plain TextView example including tutorial.

This below tag code is TextView tag with width, height and text attributes.

<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="This the text view text box." />



Note : When you create textview tag in android application then you don't have to define any external code in MainActivity.java programming file to display text box. if you write TextView tag in activity_main.xml layout file then it will be automatically called and show text on app screen.

activity_main.xml file 

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.tutorials2make.androidplaintext.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This the text view text box." />

</RelativeLayout>

Source code for MainActivity.java file

package com.tutorials2make.androidplaintext;

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) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

No comments:

Post a Comment