Tips: After booting up the emulator, actually no need close it if you want to do another testing, when you click "Run" again, it will reboot the application inside the emulator for you, it saves time.
Did you ever think of what should we do if you want to make some of the words bold, italic, underline or set a hyperlink in your apps?
It is pretty easy actually, go to the res>values>strings.xml, you may see
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">O My God,Android, this is the strings.xml!</string>
<string name="app_name">Hello,Android, the string is inside res/values</string>
</resources>
<resources>
<string name="hello">O My God,Android, this is the strings.xml!</string>
<string name="app_name">Hello,Android, the string is inside res/values</string>
</resources>
In the above example, you may actually try to insert those tag directly and see the result.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello"><b>O My God</b><i>,Android</i>,<u> this is</u> the <a href="rickiedroid.blogspot.com"> strings.xml</a>!</string>
<string name="app_name">Hello,Android, the string is inside res/values</string>
</resources>
<resources>
<string name="hello"><b>O My God</b><i>,Android</i>,<u> this is</u> the <a href="rickiedroid.blogspot.com"> strings.xml</a>!</string>
<string name="app_name">Hello,Android, the string is inside res/values</string>
</resources>
Run History > HelloAndroid.java
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNkPVEe7D2FRqFULcxncD02ImlTAdGwbFuL3-fX4mS0eDFhV7Ip-nlPWpzMSy_jN848J9yld0HWvB9z5eDHNOa0EemUsVsHNheTRejzUSGI7mT2YRP80Ljxl6-Y-0n6Bk76oVQPs0yjWk/s400/styled+text.jpg)
so what you can see is that
"O My God" become bold,
"Android" become italic,
" this is" is underlined and
"strings.xml" contains a hyperlink rickiedroid.blogspot.com
Notes: In Emulator, the hyperlink is non-clickable and you cannot highlight the words. If I'm wrong on this, please alert me.
To configure the font color, you must add on
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJcfcUTQoDnSGyRm71Qf9MMwHwjWMvAcLsgM-s5UuoYWEvJPFxo3RobJQMhrtiaTwBgGj1xgSmdrqGp3smRPQc4zhj5_DOtbIV5SP3CpALXjrBWNwTgqIRK1PjhairbkcufQ5J8jj5Y5I/s320/autocomplete.jpg)
On the right figure, shows there are actually lots of options can be used through auto complete by Eclipse.
In the example, we use textColor to change the font color.
First, we create one more xml file in res>values so that our program will be more organized.
- Insert a name for the file, File : colors.xml
Ignore all other selection, click Finish
A file in res>values>colors.xml is created.
- To insert a font color, xml element follow this method
<color name="fontname">#Hexvalue</color>
- So we should insert the xml into the colors.xml like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="fontcolor">#4FC32C</color>
<!-- kind of green in Hex value -->
</resources>
<resources>
<color name="fontcolor">#4FC32C</color>
<!-- kind of green in Hex value -->
</resources>
- Go to the res>layout>main.xml to add in one more lines,
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="@color/fontcolor"
android:text="@string/hello" />
- So you can see, under the id:textview, string:hello, the text color will follow the color:fontcolor.
- We now want to change the background color. Add in one more line to set the background color. #ffffff is white color in Hex value
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:textColor="@color/fontcolor"
android:text="@string/hello" />
you can also write android:textColor="#333333" without writing them in another xml file
ReplyDeleteyup, thanks for the suggestion. It is the best and easiest way to write as what you said for any simple application.
ReplyDeleteIf you are handling a bigger app, you will wish to monitor and manage all colors, so here comes in the xml.
I really appreciate the way you explained everything I actually learned allot just from this small tutorial. Thank you
ReplyDelete