Home  >  Q&A  >  body text

android @id和@+id的问题

伊谢尔伦伊谢尔伦2714 days ago406

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-17 16:53:43

    As you know, when we define an id for a control in xml, we use @+id/xxx. If it does not exist in R.java, the corresponding xxx variable name and value will be generated as int. If it exists, it will be used. The original int value, so each xxx has a unique identifier.
    However, when we define the ids.xml file in the resource file, we can customize the variable name of the id type in the form:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <item name="cc" type="id">213</item>
    </resources>
    

    So we can quote it as follows in the layout file:

    <Button
        android:id="@id/cc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
        

    As for what you said about @id/xxx referencing the same, it is the same as @+id/xxx.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 16:53:43

    It is also possible that a set of IDs has been customized under the values ​​folder. This can also be referenced directly using @id/xxx
    <resources>

    <item name="navigation_view" type="id" />

    </resources>

    reply
    0
  • Cancelreply