Saturday 6 January 2018

xml - What's "tools:context" in Android layout files?

itemprop="text">

Starting with a recent new version of
ADT, I've noticed this new attribute on the layout XML files, for
example:




            xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:orientation="vertical"
android:layout_width="fill_parent"

android:layout_height="fill_parent"
tools:context=".MainActivity"
/>


What
is "tools:context" used
for?




How does it even
know the exact path to the activity that is written there? Does it look at the package
of the app, inside the manifest?



Is it limited
to classes that extend Context or only activities? Is it usable for ListView items
etc.?



Answer




This is the activity the tools UI editor uses
to render your layout preview. It is documented href="https://developer.android.com/studio/write/tool-attributes#toolscontext"
rel="noreferrer">here:




This attribute
declares which activity this layout is associated with by default. This enables features
in the editor or layout preview that require knowledge of the activity, such as what the
layout theme should be in the preview and where to insert onClick handlers when you make
those from a quickfix




No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...