Skip to content

Instantly share code, notes, and snippets.

@oleggreen
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save oleggreen/221ff19cfa920757b404 to your computer and use it in GitHub Desktop.

Select an option

Save oleggreen/221ff19cfa920757b404 to your computer and use it in GitHub Desktop.
android studio layout preview attributes

Tools Attributes

link to source (android tools project site)

<FrameLayout 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:text


###tools:background


###tools:visibility


###tools:ignore This attribute can be set on any XML element, and is a comma separated list of lint issue ID's that should be ignored on this element or any of its children, recursively.

<string name="show_all_apps"
    tools:ignore="MissingTranslation">All</string>

Used by: Lint


###tools:targetApi This attribute is like the @TargetApi annotation in Java classes: it lets you specify an API level, either as an integer or as code name, that this element is known to be running on.

 <GridLayout tools:targetApi="ICE_CREAM_SANDWICH" >

Used by: Lint


###tools:locale This attribute can be set on the root element in a resource value file and should correspond to a language and optionally a region. This will let tools know what language (locale) the strings in the file are assumed to be. For example, values/strings.xml can have this root element:

 <resources xmlns:tools="http://schemas.android.com/tools" 
     tools:locale="es">

Now we know that the language used for strings in the default values folder is Spanish rather than English. Used by: Lint, Studio (to disable spell checking in non-English resource files)


###tools:context This attribute is typically set on the root element in a layout XML file, and records which activity the layout is associated with (at designtime, since obviously a layout can be used by more than one layout). This will for example be used by the layout editor to guess a default theme, since themes are defined in the Manifest and are associated with activities, not layouts. You can use the same dot prefix as in manifests to just specify the activity class without the full application package name as a prefix.

<android.support.v7.widget.GridLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity" ... >

Used by: Layout editors in Studio & Eclipse, Lint


###tools:layout This attribute is typically set in a tag and is used to record which layout you want to see rendered at designtime (at runtime, this will be determined by the actions of the fragment class listed by the tag).

<fragment android:name="com.example.master.ItemListFragment" 
    tools:layout="@android:layout/list_content" />

Used by: Layout editors in Studio & Eclipse


###tools:listitem / listheader / listfooter These attributes can be used on a (or other AdapterView children like , etc) to specify layouts to use for the list items, as well as list headers and list footers, at designtime. The tool will fill in dummy data to show a list with some representative contents.

<ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:listitem="@android:layout/simple_list_item_2" />

Used by: Layout editors in Studio & Eclipse


###tools:showIn Attribute set on the root element of a layout that 'ed by another layout. This allows you to point to one of the layouts which includes this layout, and at designtime this included layout will be rendered with the outer layout surrounding it. That allows you to view and edit the layout "in context". Requires Studio 0.5.8 or later.

<?xml version="1.0" encoding="utf-8"?>
<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:showIn="@layout/activity_main" />

Used by: Layout editor in Studio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment