Search This Blog

22 April 2010

Changing the text and background color

Building on the hello world provided by our maven archetype, we will change the colors...

mvn archetype:generate -DarchetypeCatalog=http://kallisti.eoti.org:8081/content/repositories/snapshots/archetype-catalog.xml
When prompted, choose the galatea archetype and your package/artifactId. In this case, I chose 'org.eoti.galatea', 'HelloWorld2' and '1.0-SNAPSHOT'.

First things first, let's look at what we have before we go modifying it.  Go into your new directory (named after your artifactId -- HelloWorld2 in my case) and do:
mvn install
This will deploy the existing app to your emulator (you did have your emulator running as per the linked post above, right?).  Go into the app menu in your emulator and launch your app.  You'll see a basic white-on-black "Hello World!".  Go ahead and exit the app (back arrow). Let's make that a little brighter.

We'll cheat a bit.  Copy src/main/android/res/values/strings.xml to src/main/android/res/values/colors.xml

Now, in the new colors.xml, replace the <string /> tags with these:
    <color name="black">#000000</color>
    <color name="cornsilk">#fff8dc</color>
Next, we update the main.xml...
Add this to your LinearLayout:
    android:background="@color/cornsilk"
Add this to your TextView:
    android:textColor="@color/black"
Now when we redeploy (mvn clean install), the app is now showing "Hello World!" in black on cornsilk.

No comments:

Post a Comment