Hello all…..
This is a simple tutorial to show how to create a FLEXIBLE UI for both Phone and Tablets in Android.
In the figure below you can see the result after running this tutorial.
Tablet in LANDSCAPE MODE
TABLET IN PORTRAIT MODE
TABLET IN PORTRAIT MODE – AFTER CLICKING THE LIST.
PHONE IN PORTRAIT MODE
PHONE IN LANDSCAPE MODE.
This can be achieved through Fragments.
This tutorial will have two parts.
1. In the first part I will show you how to use Fragments from API 11 (Honeycomb) and greater.
2. In the second I will show how to change it to adapt to lower versions from 1.6(Donut) using Google’s supporting Library.
I have already covered the first tutorial here..
http://www.coderzheaven.com/2013/02/17/create-layouts-change-phone-tablet-android-fragments/
Please check it before continue reading this post, because there are only small changes in the first post to make it compatible with the older version of Android.
These are the main changes you have to make.
1. Change all Activity to FragmentActivity and change the import statements like below
import android.app.Activity;
to
import android.support.v4.app.FragmentActivity;
2. Change the imports of Fragment from
import android.app.Fragment;
to
import android.support.v4.app.Fragment;
3. Now in the DetailsActivity.java change this line
getFragmentManager().beginTransaction()
.add(android.R.id.content, details).commit();To
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, details).commit();
4. match_parent is not supported in old versions so change all “match_parent” in all layouts to “fill_parent”
5. Optionally You can change the min-sdkversion in Manifest to 5.
Done.
Now you have successfully adapted Fragments to the Older version of Android.
Pingback: How to change title and Subtitle text color and size of ActionBar in Android? | Free Tools Successful Bloggers Are Using