Make sure Project View is open using the drop-down menu: View >> Tool >> Windows >> Project or Alt+1 shortcut on Windows.
Make sure you are using Android format in Project View by using the drop-down menu: Android
Expand folders to view MainActivity.kt by expanding the “app” folder and then expanding the “com.example.workshop” package.
Open the MainActivity.kt file from the Project View
Identify the different Functions listed below;
The onCreate function is like the main function in C or Java, it defines the main entry point of the program. There are also variations like onResume that are used in different situations.
The AboutMe function structures the code to be scrollable and to fill out the screen. It also has the other Composables in the order we need. You don’t need to edit this function.
The Title function is the name of your profile. We will use your name with your customized text.
The ProfilePic function will be used to share a picture of yourself. We will explore adding resources to the project and connecting them to your code.
The SelfDescription function will be used to talk about yourself. We will explore text style and Modifiers to customize your text.
The YourButton function is a customized button users can click. We will only modify the button itself and not the other content around it. The button has an “onClick” that will do something when we program it.
The YourCard function is filled with content that needs to be rendered. We will edit the content and use buttons to open and close the card. We only modify the text and button in the card to your style.
Make sure the split view is selected to see the preview.
Make sure your code compiles and you can view the preview. If you don’t see the preview, follow the prompt in the middle of the preview window.
In the Title function replace the “Example” text with your name.
Change the color to your favorite color.
Change the font size so your name fills the width of the screen.
Change the font size so your name fills half the width of the screen.
Remove the // commit and set your text to the center of the screen.
In the SelfDescription function replace the Text string with a description about
yourself.
Select the TextStyle function and then hover over it. This should bring up a list of the function parameters.
Set the text color to something you like.
Set the background color to work with your text color.
Set the text font size to be readable.
Change the font weight to be Italic
Set the font alignment
Change the font direction.
Make sure the Resource Manager is open by using the drop-down menu: View >> Tool Windows >> Resource Manager
Download a photo of yourself. If you don’t want to use your picture, download an animal that looks like you.
Add your photo the the project by using, in the Resource Manager, the + button drop-down menu: + >> Import Drawables. Find your picture in your file system, select it, and hit OK.
Replace id of the paintedResource with your the id of your photo resource. Right-click and copy the id from the Resource Manager or drag the icon from the Resource Manager into your code.
Set the content scale for the image to fit. Select and hover over the Image function to get the parameter name you need.
Make sure the Device Manager is open by using the drop-down menu: View >> Tool Windows >> Device Manager
Launch your device with the play button.
Wait for the device to launch.
Build your project using the drop-down menu: Build >> Make Project or the Ctrl+F9 shortcut on Windows.
Run your application on the device by using the drop-down menu: Run >> Run ‘app’.
Shift+F10 shortcut on Windows.
Change the card's text parameter to “Button Card”.
Remove the Text function that holds the Card Content. We will replace it with our new content.
Add a Row function to replace the content.
You can import the Row function by selecting and hovering over Row and clicking import on the menu that pops up.
Add 3 buttons to the Row content as shown:
Row {
Button(
onClick = {}
) {
Text("Left")
}
Button(
onClick = {}
) {
Text("Middle")
}
Button(
onClick = {}
) {
Text("Right")
}
}
Emulate your new buttons by using the drop-down menu: Run >> Run ‘app’
Notice this time the menu option icon has changed. This will stop your application and rebuild it then start it with the new updates.
Also, Notice the buttons that you added do nothing. Verify they are displayed.
Add context reference to the Row content. Copy the line of code as shown. Import
the LocalContext property.
Add a toast to your buttons. Use the line of code shown.
Add the Toast to the empty onClick body for each button. Rename the text to the actual button name.
Button(
onClick = { Toast.makeText(context, "Left", Toast.LENGTH_SHORT).show() }
) {
Text("Middle")
}
Run your app and test your button.
Add onClick actions to everything you can and make it do something. Use the Modifier object as shown to add a clickable action to a text. Try using a click action to change your profile name.
Change the background color.
Change your profile description.










