What is setContentView(R.layout.main)?

后端 未结 6 1313
滥情空心
滥情空心 2020-11-29 08:07

I understand that it has to do with the App layout, but when do I have to use it? I tried to look for a link that explained this method, but I couldn\'t find it. Thank you i

6条回答
  •  悲哀的现实
    2020-11-29 08:50

    In Android the visual design is stored in XML files and each Activity is associated to a design.

    setContentView(R.layout.main)
    

    R means Resource

    layout means design

    main is the xml you have created under res->layout->main.xml

    Whenever you want to change the current look of an Activity or when you move from one Activity to another, the new Activity must have a design to show. We call setContentView in onCreate with the desired design as argument.

提交回复
热议问题