Android : Developing First App using a Simple TextView



Hello everyone , today we will take a look at the android XML and Java integrated coding . In today's tutorial we will first create our basic android application and then set a text on the textview and also on the click of a button we will change the text on the text view.
  • Launch Android Studio and start a new project
  • Give the application name as you want
  • Select the checkbox for Phone and Tablet and also mention the minimum SDK version . I will be using API 18 i.e. Jelly Bean (This means that the app will be supported on all the versions of android above android Jelly Bean)
  • Select Empty Activity
  • You can name the activity as you want however a simple name will help identify what the activity actually does.
  • Click Finish



After all goes well you will see the images below . Note that for the xml page you can change the API by click on the android icon in the top right corner (This will not change the actual android version but will just change the display theme).You can also click on the Text/Design button below the activity to switch between drag and drop and actual XML coding. The Java file should also look like the given screenshot below. On the left side you can choose whichever file you want.



XML Page




Java Page

Now lets start with the basic XML activity and set some data to the text. We can do this in 2 ways.

  1. By clicking the textview and then in the lower right corner writing the data in the "text:" box
  2. By selecting the coding view for XML and then creating a tag under the textview as "text" and then writing the data.(Initially this will feel like its a bit tough but with practice it is actually more simpler and efficient than the drag and drop)




Way 1




Way 2

As we are done with our first App lets run this app. I will be using the emulator of android studio for simplicity purpose . You can also use your own smartphone . 
  • In order to run on your smartphone just turn on the USB debugging in the Developer Options of android and connect the android phone using a USB cable to your system.
  • For emulators just Run (Shift+F10) and the n select the emulators from the available emulators . If no emulator is available just click on create New Emulator and then select a Nexus 5. It is very easy to install a emulator.
Finally Run the app and the app will be installed on the system. It will look like below.



You can also change the color,size,style of the text from the XML document by typing under the textview tag in the xml document . The prompt will be automatically shown and it can be easily changed.

Now we will change the textcolor ,  the text size and orientation . It can be done by following code under that text view.

<TextView 
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Welcome to Android Tutorial"
android:textColor="#dc0606"          <--- Color Code and not actual color name 
android:textSize="25dp"
android:layout_centerHorizontal="true" android:layout_centerVertical="true"/>











Comments