Android tabs for easy implementation and customization. Requires the use of ViewPager.
-
Set the view tabs as the example on your layout. This must be configured with the
ViewPager
.<com.pc.ScrollableTabView.ScrollableTabView android:id="@+id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" />
-
In your activity, add on the method "onCreate" the following code:
ScrollableTabView scrollableTabView = (ScrollableTabView) findViewById(R.id.tabs); ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager())); scrollableTabView.setTabAdapter(new MyTabAdapter()); scrollableTabView.setViewPager(pager);
-
If you need, you can listen to page view and tab changes notification:
scrollableTabView.setOnPageChangeListener(this); scrollableTabView.setTabListener(this);
-
You can style the tabs creating a style that inherits from Tab
<style name="MyTabs" parent="Tab"> <item name="android:textAppearance">@style/MyTextAppearance</item> </style> <style name="MyTextAppearance" parent="Tab.TextAppearance"> <item name="android:textSize">22sp</item> <item name="android:textColor">@color/my_textcolor</item> </style>
-
Use the Android Action Bar Style Generator to change the background.
-
Create a layout using
TabView
:<com.pc.ScrollableTabView.TabView style="@style/MyTabs" />
Pietro Caselani - pc1992@gmail.com