In this program we are going to print a few lines of text in different colors.
First Try In Android
September 28, 2014
In order to do this, start a new project with a blank activity in Android Studio. We discussed how to setup Android Studio and create a new project in the last post.
We will save the four lines of text in res > values > strings.xml and give each string an id, so that we can reference it in our layout file.
Now, let’s save the values of the colors in an xml file. If it doesn’t already exist, create colors.xml in res > values. We can call the color values directly in the layout, but keeping the project’s colors in an xml makes them easier to re-use. I’ll pick shades of red, green, blue, and purple. You can modify the hex codes and any references to those colors will update. This makes it easy to create a color pallete for your app.
Finally, lets set up four TextView’s to display our strings in the four colors we chose. The android:text attribute of TextView can take a string or we can pass in an id front strings.xml.
Now click Run to build your project. You have just built your first app.