what is tools:context in layouts files?

Asked

Viewed 2,122 times

5

Good morning, everyone.

In some tutorials I’ve been seeing around, the creators defined this property, 'tools:context' in the main layout manager of xmls. I looked in Ricardo Lecheta’s book, but he doesn’t use it at any time.

So.. What is and what is the purpose of defining this tools:context?

Example:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

Thank you!

2 answers

4

This attribute is used to make the layout relation with an Activity.

For example. If your Activity uses a custom theme you define this theme in the manifesto, if you assign the tools:context to this Activity, when you put the Layout to edit in graphical view mode, theoretically the layouts should apply the theme defined for that Activity in the manifest.

More details about the attribute tools:... walk in here.

3


Basically the tools:context is used to tell which Activity that the UI Editor should use to choose a theme to render its layout. And this is related to the Activity Chooser in the IDE (Android Studio or Eclipse).

Response based on this Question from Stack Overflow EN

Browser other questions tagged

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