Android Tabs in XML - android

My question is simple. Is it possible to create tabs entirely in xml? My app has only one activity. I want to have 2 tabs that show the same data but in slightly different layouts. It seems like it should be but I cannot find anything on it.
TIA,
Mark

You can do something like this. Your layout for each tab would go inside a tabwidget. This will have it's limitations that you would easily get around if you employ a simple TabHost
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Tabs at bottom of screen -->
<TabWidget
android:background="#drawable/textview_top"
android:layout_weight="12"
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="0dip"
/>
</TabHost>

Related

Robust way to implement "bottom navigation tab bar"

The effect is like this:
I have investigated some methods.
Somebody use radiogroup, somebody use tabhost.
What is the simplest way?
Is there any other way?
It is not really what google recommends in there Design Guidelines for tabs, if you still want to use it, i think TabHost is the perfect way.For more see How to align your TabHost at the bottom of the screen
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</RelativeLayout>
</TabHost>
Check out this link which contains library and sample codes for each type of tab (i.e circle, underline, etc)
Using this library, You can implement different type of tab format. Your work is just import this library into your app.
And, Samples will help you to understand the different tab format.
All the Best!

Android - Tabhost (Tabwidget) issue with multiple tabs

I have five tabs in my list, you can see the three first tabs when TabActivity get started, then if I scroll to the right, the other two will also show up. Problem I have is that the next two tabs need to be tapped twice in order to start, and vice and versa for the first two tabs if the three last tabs are shown in screen.
Please, if anyone know how to solve this annoying stuff, I would be grateful.
Thanks in advance!
EDIT:
I found out that the real problem is when I scroll to end (left or right) which causes any tab to be tapped twice in order to work, someone who recognize this? I found that it can be tapped once when scrolled to the end (right or left), but only after 3 seconds. If I tap right away, it need to be tapped again to work.
My code (xml):
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"/>
</HorizontalScrollView>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
Did you wanted to try the ViewFlipper (as in the new Android market).
Here is the entire code,
Set default page for ViewPager in Android
It sounds like you might be losing focus on the tabs.
Have you tried to implement:
android.view.ViewTreeObserver.OnScrollChangedListener
And set the focus back on the TabHost when this is triggered?
You may also try playing with setOverScrollMode() in your TabHost

Arranging big number of tabs in Android

Good time!
My question is concerned to the arrange of tabs in Android apps. My app consisted 6 pages of tabs and, sure, in the running application these tabs decrease to the narrow rectangles - that's really looks bad. So, is there any cases to switch on some features in tabs to add controls with arrows (like in Windows), which are used to manage the visibility of concrete tab. For example, I have six tabs, after start user sees only three and some control to move hidden tabs on screen?
Yehh...... I think you don't need to use narrow rectangles to complete your task. You have better solution to put your TabView in ScrollView.
For example :
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<TabWidget android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
Refrence : Scrolling Tabs in Android
In order to ease your life, you can use a FrameLayout and on top of the TabWidget you can add a HorizontalScrollView with any number of buttons you want.
Then using the onClick method, when you click a specific button of this HorizontalScrollView, you can set the current tab of your activity.
This way you can also have easy theming to your "tabs"... Hope this helps.

Scrolling Tabhost at the bottom

I used the tabhost tutorial to get started with the Tabhost control.
After some play around I wanted to make the tabhost scrollable, which I figured out.
Now I want the tabhost at the bottom of the display which is just not working for me.
Switched to Relative Layout which was suggested here: iPhone-like Tabbar
My code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="horizontal" android:isScrollContainer="true">
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_alignParentBottom="true">
<RelativeLayout android:layout_height="fill_parent"
android:layout_width="fill_parent">
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:scrollbars="none"
android:layout_alignParentBottom="true">
<TabWidget android:id="#android:id/tabs"
android:layout_alignParentBottom="true" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</HorizontalScrollView>
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="2dp" />
</RelativeLayout>
</TabHost>
I need a hint why it's not working / how this would work. I tried with relative layout and layout_alignParentBottom="true" now it's there a few times (in the HorizontalScrollView and the TabWidget)
Thanks to Arve leading me to "custom controls" I found a promising project:
https://github.com/honcheng/ScrollableTabHost-for-Android
I hope some others looking for this kind of tabhost can use it :)
A possible library to help you do this:
http://code.google.com/p/androidtabs/
From their project description:
Due to limitation of Android Tab component I created a custom TabWidget that I am using in couple different projects already. The widget allows us to add custom background and use custom icons, tabs can be Top/Bottom aligned.
EDIT: I have not tested this myself, but it looks promising.

Is it possible to create Horizontal Tabs in Android OS?

I'm using the TabHost and TabWidget to create some tabs for an Android application. I see that the tabs show up vertically one next to the other. Is there any way to make tabs that are aligned horizontally (one on top of the other) ?.
I'm creating the tabs like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
</FrameLayout>
</LinearLayout>
Something like this is what I need to do:
Try this one: https://code.google.com/p/themissingtabwidget/ . This is an open-source implementation based on the original tab widget that also works in horizontal mode.
I'm not certain, but I don't think there's much you can do with the default behavior. Android's tab support in general seems a bit clunky to me. But let me know if you do get this working -- I might be able to use it myself!
FWIW, I did my own tab behavior using image buttons and other control elements. In my case, I was trying to come up with tabs that didn't use so much screen real estate.

Categories

Resources