Create button with round background

To create button with round background, create /res/drawable/roundbackground.xml to define round background drawable.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:padding="10dp">
<solid android:color="@android:color/background_dark"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
</shape>


Apply "roundbackground" to the background of button.
<RelativeLayout 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" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".MainActivity" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/roundbackground"
android:text="Button with round background"
android:textColor="@android:color/white"
/>

</RelativeLayout>

Button with round background


Creating alias resources

When you have a resource that you'd like to use for more than one device configuration (but do not want to provide as a default resource), you do not need to put the same resource in more than one alternative resource directory. Instead, you can (in some cases) create an alternative resource that acts as an alias for a resource saved in your default resource directory.

Reference: http://developer.android.com/guide/topics/resources/providing-resources.html#AliasResources

Refer to the last exercise of Alternative Resources. Both /res/layout-land/activity_main.xml and /res/layout-large/activity_main.xml have the same layout. We can create alias resources refer to a common xml file.

Create: /res/values-land/refs.xml and /res/values-large/refs.xml.
Both define resource of type="layout" with name="activity_item_list", refer to the same layout file /res/layout/activity_main_horizontal.xml
<resources>
<item type="layout" name="activity_main">@layout/activity_main_horizontal</item>
</resources>


Create the common layout /res/layout/activity_main_horizontal.xml. Actually it's the original /res/layout-land/activity_main.xml and /res/layout-large/activity_main.xml.
<RelativeLayout 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" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:src="@drawable/ic_launcher"
tools:context=".MainActivity" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/myqualifier"
tools:context=".MainActivity" />
</LinearLayout>

</RelativeLayout>


Delete the original duplicated layout, /res/layout-land/activity_main.xml and /res/layout-large/activity_main.xml.

It have the same result of the last exercise, Providing Alternative Resources.

Providing Alternative Resources

App developers can provide alternative resources to support specific device configurations. For instance, you should include alternative drawable resources for different screen densities and alternative string resources for different languages. At runtime, Android detects the current device configuration and loads the appropriate resources for your application.

Reference: http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

It's a example to provide alternative resources for various configurations.

Galaxy Nexus (4.0.4) in landscape orientation

Galaxy Nexus (4.0.4) in portrait orientation

HTC Flyer (3.2.1) in landscape orientation

HTC Flyer (3.2.1) in portrait orientation


Create a Android Application Project with Build SDK Android 4.1 (API 16) and Minimum Required SDK API 11: Android 3.0 (Honeycomb), select BlankActivity, Navigation Type of None.

Modify/Create resources as list below:

/res/values/strings.xml
<resources>

<string name="app_name">AndroidQualifier</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>

<string name="myqualifier">DEFAULT qualifier</string>

</resources>


/res/values-land/strings.xml
<resources>
<string name="myqualifier">-land qualifier</string>
</resources>


/res/values-large/strings.xml
<resources>
<string name="myqualifier">-large qualifier</string>
</resources>


/res/values-v11/strings.xml
<resources>
<string name="myqualifier">-v11 qualifier</string>
</resources>


/res/values-v14/strings.xml
<resources>
<string name="myqualifier">-v14 qualifier</string>
</resources>


/res/layout/activity_main.xml, LinearLayout in vertical.
<RelativeLayout 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" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:src="@drawable/ic_launcher"
tools:context=".MainActivity" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/myqualifier"
tools:context=".MainActivity" />
</LinearLayout>

</RelativeLayout>


/res/layout-land/activity_main.xml
/res/layout-large/activity_main.xml, LinearLayout in horizontal.
<RelativeLayout 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" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:src="@drawable/ic_launcher"
tools:context=".MainActivity" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/myqualifier"
tools:context=".MainActivity" />
</LinearLayout>

</RelativeLayout>

In this exercise both /res/layout-land/activity_main.xml and /res/layout-large/activity_main.xml have the same layout. It can defined in one common layout file with alias resources.


10.9% of Android devices running Ice Cream Sandwich

According to the updated distribution data from Android Developers Site, there are 10.9% of Android devices running Ice Cream Sandwich (Android 4).  To know more, visit: http://developer.android.com/about/dashboards/index.html.

It can be predicted that Ice Cream Sandwich and post-Ice Cream Sandwich devices (that means 'Fragment-ready') will dominate in the coming future.



Android 4.1 Jelly Bean on HTC One X



#BoycottApple

BoycottApple

BoycottApple

BoycottApple

BoycottApple

BoycottApple

BoycottApple



Error: The method onItemSelected(String) of type ItemListActivity must override a superclass method

It MAY BE happen if you new a project using the new Android SDK Revision 20: Eclipse complain with errors of:
- The method onItemSelected(String) of type ItemListActivity must override a superclass method
- The method onItemSelected(String) of type new ItemListFragment.Callbacks(){} must override a superclass method



Checking the updated System requirements of Android SDK, only JDK 6 is officially supported:



To fix it: correct Compiler compliance level to 1.6.

- Right click your project, select Properties.


-  Select Java Compiler tab, change Compiler compliance level to 1.6.


- Alternatively, you  can click Window -> Preferences, then select Java -> Compiler to change Compiler compliance level to 1.6 for the whole workspace.


Then clean and re-build. Now fixed with 0 errors.