android-to merge the indicators of the toggle tabs onto the Actionbar

Source: Internet
Author: User

Recently more busy, long time no update blog. The first day of the national Day did not come home, idle can put before you want to post something to write.

Students who have used the smooth and Fuubo two excellent third-party microblogging clients should have seen their home page UI, such as:

  

  

They put the switching tabs indicator on the Actionbar, which saves the space devoted to tabs. We can have more visual space to browse the main microblogging content.

The tab switcher on the Actionbar is a custom component Tabbarview.

Declare a tabbarview and set a viewpaper, add Tabbarview in the Oncreateoptionsmenu menu method to show Actionbar toggle indicator on the right side of tabs

@Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); View v=(View) Menu.finditem (r.id.action_settings). Getactionview (); Tabbarview=(Tabbarview) V.findviewbyid (R.id.tab_bar); Tabbarview.setstripheight (10); Msectionspageradapter=NewSectionspageradapter (Getfragmentmanager ()); //Set up the Viewpager with the sections adapter.Mviewpager =(Viewpager) Findviewbyid (R.id.pager);        Mviewpager.setadapter (Msectionspageradapter);        Tabbarview.setviewpager (Mviewpager); return true; }

Add Tabbarview components to the Menu.xml:

<menu xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    tools:context=" Com.example.demo.MainActivity ">    <item        android:id= "@+id/action_settings"        android:orderincategory= "Android"        : Showasaction= "Never"        android:actionlayout= "@layout/custom_ab"/></menu>

Effect:

  

Demo:https://github.com/syun0929/tabbarview

  

android-to merge the indicators of the toggle tabs onto the Actionbar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.