Android Tutorial 131
import android.graphics.drawable.ColorDrawable;
...
String myString = getResources().getString(R.string.hello);
int myColor =
getResources().getColor(R.color.prettyTextColor);
float myDimen =
getResources().getDimension(R.dimen.textPointSize);
ColorDrawable myDraw = (ColorDrawable)getResources().
getDrawable(R.drawable.redDrawable);
Some resource types, such as string arrays, are more easily added
to resource files by editing the XML by hand. For example, if we go
back to the strings.xml file and choose the strings.xml tab, we can
add a string array to our resource listing by adding the following
XML element:
<?xml version=”1.0” encoding=”utf-8”?>
Save the strings.xml file, and now this string array named “flavors”
is available in your source file R.java, so you can use it
programmatically in resourcesroundup.java like this:
String[] aFlavors =
getResources().getStringArray(R.array.flavors);