What does "android.R.id.content" mean?

Asked

Viewed 1,261 times

1

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?

3 answers

2


Explanation: The android.R.id.content It is a constant that has the value of an Integer number, which is the address referenced to such content, which is declared in R.java which is a file that is generated every time you der Build in the project.

Explanation of contentin itself:

android.R.id.content - Is an integer number used to reference or identify the element used as the basis of your View.

Every element you create, you will have an address for it on R.java, this android.R.id.content is just an easier way to reference your element.

Is also used android.R.layout.nomedolayout to reference XML layouts in your application.

They are Resources for your application, so they stay in the folder res of your project Just like there are others:

android.R.strings.nomedastring - for strings registered 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 locations, or to change only one place when you want to change a pattern, such as a title that is used in all Activity's of your project, Voce want to change it and not have to change at all Layout's you use a string in Layout and then just change it into Strings.xml

Color’s has the same goal as strings but would be, in this case, colors.

Attr’s, are attributes, but consist of the same goal.

Styles are used to create themes and modify Android default styles for Android components.

These properties cited, are used in the Visual of your Activity that is, in the Layout.

Note: The layouts are in res/layout.

  • Thanks! I guess I wasn’t specific enough. My question is about android.R.id.content exactly. I don’t know what "content is".

  • Well, I thought this was kind of obvious, sorry, I’ll edit the answer.

  • 1

    I got it, and I marked it as an answer. Thanks!

  • Arrange, I thank you.

0

Is the value of root view. "android." is not used for referencing resources from the app itself. To your own resources, use only R., nay android.R.

-2

The android.R.id.content and a generic identifier for the view root element.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.