1

I wanna know how to access strings & colors & dimens of xml files programmatically.

Is there any easy way to access it ???

kimkevin
  • 2,202
  • 1
  • 26
  • 48

2 Answers2

2

You can use getResource of your activity to get the string, color ,etc from your values folder of your project.

sample:

String m_string = getResources().getString(R.string.app_name); //string xml
float m_dimension = getResources().getDimension(R.dimen.dimension); //dimens xml
int m_color = getResources().getColor(R.color.blue); //color xml
Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63
2

You'll want Resources.

In an activity, you can use getResources() to retrieve that object, and then simply use

Resources res = getResources();
String string = res.getString( R.string.string_id );
int color = res.getColor( R.color.color_id )

etc.

323go
  • 14,143
  • 6
  • 33
  • 41