Friday, April 2, 2010

Android resources (eng)

Do you know Android SDK contains all resources used by standard widgets? Icons, animations, styles and so on.
They are placed on the <Android SDK folder>/data/res folder. And it is possible to use them directly, so it is not necessary to add them into project.


For example, here is a checked list view that uses starts instead of habitual marks:

To do that just do next:
  • Define list view item layout (let call it star_checked_item). You can use standard layout for android.R.layout.simple_list_item_checked - layouts/simple_list_item_checked.xml file.
        <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+android:id/text1"
            android:layout_width="fill_parent"
            android:layout_height="?android:attr/listPreferredItemHeight"
            android:textAppearance="?android:attr/textAppearanceLarge"

            android:gravity="center_vertical"
            android:checkMark="@android:drawable/btn_star" <!-- Mark style -->
            android:paddingLeft="6dip"
            android:paddingRight="6dip"/>
  •  Use this layout in list view adapter
         ArrayAdapter adapter = new ArrayAdapter(this, R.layout.star_checked_item); 
         list.setAdapter(adapter);

No comments:

Post a Comment