If I have a button with an attribute of
android:text="+1"
should it be included in the @string file or is it fine to be hardcoded in the activity_main?
Yes you can include them in the strings.xml
(if being treated as strings , otherwise you should save them with <integer>
tag). You don't need to explicitly put them in layout.
If being treated as strings (As in your case , you are setting it as string)
<string name="my_integer_value">3</string>
So it is accessible as android:text="@string/my_integer_value"
If being treated as Integers
<integer name="my_integer_value">3</integer>
The answer depends on what the string is being used for. strings.xml
is for UI strings that may be different in different configurations, most commonly different locales/languages. String constants that are meaningful to the app should generally not be in strings.xml
.
Since this string is a button label, it should probably go in strings.xml
.