Permalink
Browse files

basic tabs with minor styling

  • Loading branch information...
1 parent 1de2f33 commit 08d03ecfb298566377cd5029e347e9f9b6c5db29 @nitindhar7 committed Jan 31, 2012
View
@@ -0,0 +1 @@
+bin/
View
@@ -15,10 +15,13 @@
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
-
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity
+ android:name=".TabContentActivity"
+ android:theme="@android:style/Theme.NoTitleBar" >
+ </activity>
</application>
</manifest>
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Deleted file not rendered
Deleted file not rendered
Deleted file not rendered
View
Binary file not shown.
@@ -14,11 +14,12 @@
public static final int ic_launcher=0x7f020000;
}
public static final class id {
- public static final int tab=0x7f050000;
- public static final int tabDivider=0x7f050003;
- public static final int tabLabel=0x7f050001;
- public static final int tabSelectedDivider=0x7f050002;
- public static final int tabSplitter=0x7f050004;
+ public static final int tab=0x7f050001;
+ public static final int tabDivider=0x7f050004;
+ public static final int tabLabel=0x7f050002;
+ public static final int tabSelectedDivider=0x7f050003;
+ public static final int tabSplitter=0x7f050005;
+ public static final int tabcontainer=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
View
@@ -4,20 +4,29 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
- <TabWidget
- android:id="@android:id/tabs"
- android:layout_width="fill_parent"
- android:layout_height="48dp"
- android:background="#000"
- android:gravity="center_horizontal" />
-
- <FrameLayout
- android:id="@android:id/tabcontent"
+ <LinearLayout
+ android:id="@+id/tabcontainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:fadeScrollbars="false"
- android:fadingEdge="none"
- android:scrollbars="@null" >
- </FrameLayout>
+ android:orientation="vertical" >
+
+ <TabWidget
+ android:id="@android:id/tabs"
+ android:layout_width="fill_parent"
+ android:layout_height="48dp"
+ android:background="#000"
+ android:gravity="center_horizontal" >
+ </TabWidget>
+
+ <FrameLayout
+ android:id="@android:id/tabcontent"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:fadeScrollbars="false"
+ android:fadingEdge="none"
+ android:scrollbars="@null" >
+ </FrameLayout>
+
+ </LinearLayout>
</TabHost>
@@ -11,7 +11,7 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
- textview.setText("This is the Artists tab");
+ textview.setText(getIntent().getStringExtra("content"));
setContentView(textview);
}
}
@@ -6,11 +6,17 @@
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.LinearLayout.LayoutParams;
import android.widget.TabHost;
+import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;
public class TabTutorialActivity extends TabActivity {
+ private static final LayoutParams params = new LinearLayout.LayoutParams(
+ LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.5f);
+
private static TabHost tabHost;
private static TabHost.TabSpec spec;
private static Intent intent;
@@ -29,19 +35,45 @@ public void onCreate(Bundle savedInstanceState) {
tabHost = getTabHost();
tab = inflater.inflate(R.layout.tab, getTabWidget(), false);
+ tab.setLayoutParams(params);
label = (TextView) tab.findViewById(R.id.tabLabel);
label.setText("HOME");
divider = (TextView) tab.findViewById(R.id.tabSelectedDivider);
divider.setVisibility(View.VISIBLE);
intent = new Intent(TabTutorialActivity.this, TabContentActivity.class);
+ intent.putExtra("content", "Content for HOME");
spec = tabHost.newTabSpec("home").setIndicator(tab).setContent(intent);
tabHost.addTab(spec);
tab = inflater.inflate(R.layout.tab, getTabWidget(), false);
+ tab.setLayoutParams(params);
label = (TextView) tab.findViewById(R.id.tabLabel);
- label.setText("HOME");
+ label.setText("USERS");
intent = new Intent(TabTutorialActivity.this, TabContentActivity.class);
- spec = tabHost.newTabSpec("home").setIndicator(tab).setContent(intent);
+ intent.putExtra("content", "Content for USERS");
+ spec = tabHost.newTabSpec("users").setIndicator(tab).setContent(intent);
tabHost.addTab(spec);
+
+ tabHost.setOnTabChangedListener(new OnTabChangeListener() {
+ @Override
+ public void onTabChanged(String tag) {
+ clearTabStyles();
+ View tabView = null;
+ if (tag.equals("home")) {
+ tabView = getTabWidget().getChildAt(0);
+ }
+ else if (tag.equals("users")) {
+ tabView = getTabWidget().getChildAt(1);
+ }
+ tabView.findViewById(R.id.tabSelectedDivider).setVisibility(View.VISIBLE);
+ }
+ });
+ }
+
+ private void clearTabStyles() {
+ for (int i = 0; i < getTabWidget().getChildCount(); i++) {
+ tab = getTabWidget().getChildAt(i);
+ tab.findViewById(R.id.tabSelectedDivider).setVisibility(View.GONE);
+ }
}
}

0 comments on commit 08d03ec

Please sign in to comment.