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.