- What does the Android R class do?
Answer:
It manages the resources in an Android app, for example: ids, colors in the
colors.xml file and strings in the strings.xml file. You can
use the id to create a Java object like this:
TextView tv = findViewById(R.id.txt_temp);
- Show how display a string dynamically from the strings.xml resource file.
Answer:
TextView tv = findViewById(R.id.txt_name);
tv.setText(getString(R.string.first_name));
- Show how to change a color dynamically from the colors.xml resource file. Answer:
LinearLayout layout = findViewById(R.id.main);
layout.setBackgroundColor(getColor(R.color.purple));
// or
layout.setBackgroundColor(0xFFFF00FF);