Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Projects Templates

i'm new to Android Programming and now following official android training here

i'm actually confused since courses are different from what i get in Android Studio 1.4.1, and i have some questions :

  • where can i get back the standard "blank activity" instead of that new one with floating button ? and,
  • why there are two XML layout definitions for each created activity ?

thank you

like image 323
Anas Avatar asked Nov 26 '25 13:11

Anas


1 Answers

There is a Template called "Empty Activity" in "Create New Project" dialog. It seems to be equivalent to the former "Blank Activity".

Create New Project dialog

And it has a single layout.xml.

Note that it is not explicitly equivalent to the former "Blank Activity" because it is gotten rid of any Menus. However, I think it is suitable for your tutorial purpose for its simplicity.

Besides Floating Button, the current "Blank Activity" has an ActionBar (implemented with Toolbar) and nested layout (using inclusion). It may look quite complex for newbies.


How can I get the actual layout ... ?

You can get the "Blank Activity" template's actual layout by including content_main.xml into activity_main.xml. The structure is below:

<android.support.design.widget.CoordinatorLayout>

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

    <RelativeLayout>
        <TextView />
    </RelativeLayout>

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

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

In which I can add some TextViews?

It is the RalativeLayout shown above. Set an id to the RelativeLayout and find it.

In content_main.xml (set id):

<RelativeLayout
    android:id="@+id/content_viewgroup"
    ...
    >

In onCreate (find it):

RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.content_viewgroup);

And add your textView to the relativeLayout instead of setting it as the contentView.

relativeLayout.addView(textView); // instead of setContentView(textView);
like image 132
hata Avatar answered Nov 28 '25 03:11

hata



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!