Introduction
My last article was on the use of basic fragments. It showed how and when to use a fragment. You can find the article at http://www.c-sharpcorner.com/UploadFile/2fd686/fragments-in-android/
This article shows one of the major uses of fragments.
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <!-- state selected -->
- <item android:state_selected="true">
- <shape android:shape="rectangle">
- <gradient
- android:startColor="#555555"
- android:centerColor="#444444"
- android:endColor="#333333"
- android:angle="90"/>
- <padding android:left="7dp"
- android:top="7dp"
- android:right="7dp"
- android:bottom="7dp" />
- <stroke
- android:width="2dip"
- android:color="#555555" />
- </shape>
- </item>
- <!-- state normal -->
- <item>
- <shape android:shape="rectangle">
- <gradient
- android:startColor="#222222"
- android:centerColor="#181818"
- android:endColor="#111111"
- android:angle="90"/>
- <padding android:left="7dp"
- android:top="7dp"
- android:right="7dp"
- android:bottom="7dp" />
- <stroke
- android:width="2dip"
- android:color="#222222" />
- </shape>
- </item>
- </selector>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/tabsLayout" android:layout_width="fill_parent"
- android:layout_height="fill_parent" android:background="@drawable/tab_style"
- android:gravity="center" android:orientation="vertical">
- <ImageView android:layout_width="fill_parent" android:layout_height="wrap_content"
- android:layout_weight="1"
- android:id="@+id/tab_icon" />
- <TextView
- android:id="@+id/tab_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="#ffffff"
- android:text="asdfads"
- android:paddingTop="5dp"
- android:paddingBottom="2dp"
- android:textSize="14sp"
- />
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="#AA1111">
- <TextView
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:text="This is Tab 1"
- android:textSize="20sp"
- android:textColor="#dddddd"
- android:layout_centerInParent="true"
- />
- </RelativeLayout>



arigatooPosted Sep 11, 2013, 12:48 PM
Great!! thanks a lot :D
koutuk itPosted Jun 18, 2013, 12:38 PM
thanks Bro U save my day
santhosh kumarPosted May 4, 2013, 2:24 PM
Good work. Thanks. Could you please tell me How can i start a new fragment under same tab? Pressing back button should take me to previous fragment. Thanks in advance.
elbert yagayaeditedPosted Mar 14, 2013, 3:51 AMEdited Mar 14, 2013, 5:35 AM
Awesome! Cheers!