0

Hi =) I was just curious, when i am creating an android project in Android Studio, which i believe i have the most recent version of, with a blank activity or whatever it makes a main activity for example... And this main activity comes with 2 xml files, activity-main.xml and content-main.xml Well i have several reference guides and tutorial books that all say to navigate to the activity-main.xml to edit the layout of the actual app. But the contents of activity-main.xml consist of:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="blahblahblah">

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_crime"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

Im assuming this is only for the newer android versions that come with the floating action button because this file from what i can see controls the action bar and action button... But the app layout for everything else is actually contained in content-main.xml I was just curious what happened to split these to files apart?

Pixelknight1398
  • 537
  • 2
  • 10
  • 33
  • You could do the same thing in older android versions. The `` tag isn't new. It was added for [layout reuse](http://developer.android.com/training/improving-layouts/reusing-layouts.html). – OneCricketeer Mar 15 '16 at 20:36

1 Answers1

1

As far I know, there is no difference. You can delete both and go ahead with your own 'my-own-activity.xml'

What is required are these 2 things:

  1. Your xml file includes the xml header
  2. you set the correct xml file in 'setContent()' of activity's onCreate()

Edit: as suggested here: https://stackoverflow.com/a/32880945/1750013 obviously these two XMLs work towards creating a more readble code but there is no difference when it comes to functionality i.e. both are plain XML files.

Community
  • 1
  • 1
Rusheel Jain
  • 843
  • 6
  • 20
  • There is a slight difference. The activity *includes* the content and it is designed to be used for the overall theme of the application. You can switch out the content much like Fragments and keep the same Activity displayed. – OneCricketeer Mar 15 '16 at 20:34
  • @cricket_007 agreed. But that is just for readability. One can always delete both of these files and manually make a single new xml file – Rusheel Jain Mar 15 '16 at 20:37
  • Ahh i understand now. Thank you – Pixelknight1398 Mar 15 '16 at 20:50