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 Activity >> Click Next Button.
  4. In the Configure Your Project Dialog:
  5. A window with caption Building Examples Gradle Project shows the Gradle files that are created.
  6. Check these project files that have been created:
          activity_main.xml   MainActivity.java
  7. Select Main Menu Tools >> AVD Manager
  8. In the Your Virtual Devices Dialog:
    Create Virtual Device
  9. In the Select Hardware Dialog:
    Select Phone >> Galaxy Nexus.
    Click Next.
  10. In the System Image Dialog, select Lollipop >> Click Download >>
        Click Next to verify the configuration
  11. In the Android Virtual Device Dialog, click Finish.
  12. Change the text attribute of the TextView tag:
    android:text="Hello, my name is Stan."
    
    for the LinearLayout tag.
  13. Compile and run the project:
    Select Run in the main menu of Android Studio >> Run App.
    The Emulator Window appears for testing the app.
  14. Change the title of the application by modifying the strings.xml files located in the folder
    app/res/values
    
  15. Now replace the ConstraintLayout in the XML file with a LinearLayout like we did in class.
    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.
  16. Add the attribute setting
    android:gravity="center"
    
    to the LinearLayout tag. This centers the text horizontally and vertically within the TextView widget.
  17. Add source code headers with name, project number, and submit date. Here are the resulting layout files:
    activity_main.xml   MainActivity.java.