I'm following a tutorial here and it references this in this line:
getSupportFragmentManager().findFragmentById(android.R.id.content);
What is the meaning of this identifier?
I'm following a tutorial here and it references this in this line:
getSupportFragmentManager().findFragmentById(android.R.id.content);
What is the meaning of this identifier?
Explanation: The android.R.id.content
is a constant that has the value of a Integer, which is the address referenced to such content, which is declared in R.java
which is a file that is generated every time you build in the project.
Explanation of content
itself:
android.R.id.content
- is an integer used to reference or identify the element used as the basis of your View
.
Each element you create will have an address for it in R.java
, this android.R.id.content
is just an easier way to reference your element.
android.R.layout.nomedolayout
is also used to reference XML Layouts in your application.
They are Resources of your application, so they are in the res
folder of your project Just like there are others:
android.R.strings.nomedastring
- for strings entered in res/values/strings.xml
android.R.color.nomedacor
- for colors registered in res/values/colors.xml
android.R.attr.nomedoatributo
- for attributes declared in res/values/attrs.xml
android.R.style.nomedoestilo
- for styles that are in res/values/styles.xml
Details:
Strings are used to reuse the same string for multiple places, or to change only one place when you want to change a pattern, such as a title that is used in all% s of your project, you you want to change it and not have to change at all Activity
's you use a string in Layout
and then just change it in Layout
Color's has the same goal as the strings but would, in this case, color.
Attr's are attributes, but consist of the same goal.
Styles are used to create themes and modify standard Android styles for Android components.
These properties are used in the Visual of your Strings.xml
, that is, Activity
.
Note: Layouts are in Layout
.
This is the root view value. "android." is not used to reference resources
of the app itself. For your own resources
, use only R.
, not android.R
.
The android.R.id.content
is a generic identifier for the root element of the view.