To Lecture Notes

TextDisplay Example

Goal

Directions

  1. Open Android Studio.
  2. Select "Create New Project."
  3. In the Select a Project Template Dialog:
    Select Phone and Tablet >> Empty Views Activity >> Next
  4. In the Configure Your Project Dialog:
  5. Check these project files that have been created:
          activity_main.xml   MainActivity.java
  6. In the Main Menu, select Tools >> Device Manager
  7. Click the + Button (Add a new device), Select Create Virtual Device.
  8. In the Add Device Dialog Window, select
    Medium Phone >> Next. Then click Finish.
    Click Yes in the Confirm Download Window.
    After the device has finished downloading, click Finish.
  9. In the XML layout file activity_main.xml, change the text attribute of the TextView tag:
    android:text="Hello, my name is Stan."
    
  10. Compile and run the project:
    Select Run in the main menu of Android Studio >> Run App.
    The Emulator Window appears for testing the app.
  11. Now replace the ConstraintLayout in the XML file with a LinearLayout.
    Replace
    <androidx.constraintlayout.widget.ConstraintLayout
    
    with
    <LinearLayout
    
    and replace
    </androidx.constraintlayout.widget.ConstraintLayout>
    
    with
    </LinearLayout>
    
    Delete Line 3 where the namespace app is defined, and delete lines 14 through 17 which are not needed in the LinearLayout.
  12. Add the attribute setting
    android:gravity="center"
    
    to the LinearLayout tag. This centers the text horizontally and vertically within the TextView widget.
  13. Add source code headers with name, project number, and submit date. Here are the resulting layout files:
    activity_main.xml   MainActivity.java.