Android - iPhone Style Tabhost

How to do Tab Host like Iphone in android?

You can apply the custom shape and selector for tab.

shape_tab_selected.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<!-- radius should be half of the desired TabLayout height -->
<corners android:radius="15dp" />
<solid android:color="@color/colorWhite"/>

</shape>

shape_tab_un_selected.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<!-- color of the selected tab -->
<solid android:color="@android:color/transparent" />


</shape>

selector_tab.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- drawable for selected tab -->
<item
android:drawable="@drawable/shape_tab_selected"
android:state_selected="true"/>

<!-- drawable for unselected tab -->
<item
android:drawable="@drawable/shape_tab_unselected"
android:state_selected="false"/>

</selector>

Add tab layout in your activity layout and set selector_tab as tabBackground.

<com.google.android.material.tabs.TabLayout 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorGray"
app:tabGravity="fill"
app:tabBackground="@drawable/selector_tab"
app:tabIndicatorColor="@android:color/transparent"
app:tabIndicatorHeight="0dp"
app:tabMode="fixed"
app:tabRippleColor="@null"
app:tabSelectedTextColor="@color/colorBlack"
app:tabTextColor="@color/colorBlack" />

Customize other properties according to your need. You can find more about TabLayout here

That's all.

Happy Coding! :)

How to create a custom tabbar in android to look like an iphone tabbar?

There's nothing that says the TabHost in a tabbed layout needs to be above the tab content area, so feel free to stick it wherever. But please don't put tabs on the bottom just because you can; Android users aren't used to this and you need to have a better reason than "it looks old-school" for violating UX expectations.

If you just want to fix the look of individual tabs themeselves, you can use TabSpec's setContent(View v) method to setup a custom view for a tab. Also see the source code to the Google IO 2010 Schedule app. You can definitely spruce up tabs this way in lots of good ways without messing about with user's understandings of what Android tabs are and how they function.

iPhone- like tab bar in Android?

There's a tutorial for creating a "Tab Layout" on the android dev site:

You can implement your tab content in
one of two ways: use the tabs to swap
Views within the same Activity, or use
the tabs to change between entirely
separate activities

Tab Layout

(source: android.com)

android tabwidget need help

I had customized android tab to look like iPhone UITabBar, found here:

  • Android - iphone style tabhost : my answer
  • Android - iphone style tabhost : another good effort

OR you can implement your own tabs using RadioGroup but requires hell of work,
to implement RadioGroup you can refer to this project. It uses Iphone like SegmentedControl, and you can use it by yourself to look like iphone tab.

Badge on Android TabHost

Android ViewBadger may be the solution for you. (FYI, i haven't implemented it yet)

Here is the snap you can have as an output by this solution:

Sample Image

iOS Tab Replacement in Android

You can use the native tabs and style it to seem like iOS ones.

Use Fragments, and store/reload the "Natigation flow" at the onPause/onRestore methods in each Fragment or in the FragmentActivity when you change form one fragment to an other.

BTW, please don't do that. If you studied Pure Android, what's the point do you want to achieve? Android is Android and iOS is iOS, do not mix them please.

UPDATE: 3 September 2017

An other, and imho better, approach to do so is make use of the Bottom Navigation. Take a look to materialdocs to learn how to use it.

How to use custom iPhone tab in FragmentActivity?

Solved it! Finally! After testing other resources that I referred to, I realized that layout_alignParentBottom in RelativeLayout does not give any outcome. Hence I tried aligning the TabWidget to the bottom instead, and it worked!

This is my main.xml that contain TabHost and TabWidget.
http://pastie.org/pastes/5188297/text?key=lqfp3jnofs5kgsvslm3yg

Keep the tab_indicator.xml / the settings for the text and image like this : http://pastie.org/pastes/5187408/text?key=qxxa5xxrhsburebllyhmw

And here is the a custom iPhone tab that uses FragmentActivity :

P/S : Sorry if my Java file is confusing, I'm new and if there is anything I did wrong, do tell me.

Sample Image



Related Topics



Leave a reply



Submit