Tools: context = & quot;. MainActivity,

Source: Internet
Author: User

Tools: context = ". MainActivity,

<TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true"        android:text="@string/hello_world"        tools:context=".MainActivity" />

I have never understood the "tools: context =". MainActivity "sentence. I checked it today and found it like this:

 

Tools: context = "activity name" is not packaged into the APK. Only the Layout Editor of ADT sets the corresponding rendering context in your current Layout file, indicating that the rendering context of your current Layout is the activity corresponding to the activity name, if Theme is set for this activity in the manifest file, the Layout Editor of the ADT will render your current Layout based on the Theme. That is to say, if the MainActivity you set has a Theme. light (others can also be used), then Theme is what you see in the visual layout manager. light. It is only used to show you what you see is what you get.

 


What is the role of context in android?

Context literally refers to the Context, which is located in the android. content. Context of the framework package. In fact, this class is of the LONG type, similar to the Handle in Win32. Many methods need to use Context to identify the caller's instance. For example, the first parameter of Toast is Context. Generally, this is directly used in the Activity to represent that the caller's instance is Activity, when the onClick (View view) method of a button is used, an error is reported when this method is used. Therefore, ActivityName may be used. this is mainly because the classes that implement Context mainly have several models unique to Android, Activity and Service.

Context provides an interface for global information about the application environment. It is an abstract class and its execution is provided by the Android system. It allows you to obtain resources and types characterized by applications. Start application-level operations at the same time, such as starting Activity, broadcasting, and receiving intents.

Update ADT20 and tools: context = "" appears.

Tools: context = "activity name" is not packaged into the APK. Only the Layout Editor of ADT sets the corresponding rendering context in your current Layout file, indicating that the rendering context of your current Layout is the activity corresponding to the activity name, if Theme is set for this activity in the manifest file, the Layout Editor of the ADT will render your current Layout based on the Theme. That is to say, if the MainActivity you set has a Theme. Light (others can also), you can view it in the visual layout manager.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.