22.Android Very convenient Sliding tab page

Source: Internet
Author: User

22.Android Very convenient Sliding tab page

    • Easy to swipe tabs on Android
      • Objective
      • Easyslidingtabs Property
      • Easyslidingtabs layout
      • Fragmentpageradapter
      • Easyslidingtabs setting tab background
      • GitHub Portal

Objective

In fact, sliding tab page is very common, online search is also a lot. But there are not many libraries that are easy, simple, bug-friendly, and extensible. Many want to do the Sliding tab page often think of a variety of unreliable libraries, although not difficult, but easy to pit themselves.

Original Samsung bottom app big God Jiangecho provide technical support

Easyslidingtabs Property

The names of these properties are very simple in English, not difficult!

    <declare-styleable name="Easyslidingtabs">        <attr name="Easyindicatorcolor" format="Color" />        <attr name="Easyunderlinecolor" format="Color" />        <attr name="Easytabtextcolor" format="Color" />         <attr name="Easyselectedtagtextcolor" format="Color" />         <attr name="Easydividercolor" format="Color" />        <attr name="easyindicatorheight" format="Dimension" />        <attr name="easyunderlineheight" format="Dimension" />         <attr name="easydividerpadding" format="Dimension" />         <attr name="easytabpaddingleftright" format="Dimension" />        <attr name="Easytabbackground" format="Reference" />        <attr name="Easyscrolloffset" format="Dimension" />         <attr name="Easyshouldexpand" format="boolean" / >        <attr name="easytextallcaps" format="boolean" />        <attr name="easyindicatordrawable" format="Reference" / >    </declare-styleable>
Easyslidingtabs layout

It's really very simple >. <.

Activity_main.xml

<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"xmlns:app="Http://schemas.android.com/apk/res-auto"xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="Match_parent"android:layout_height="Match_parent"android:orientation="Vertical"tools:context=". Mainactivity "> <com. Camnter. Easyslidingtabs. Widgets. EasyslidingtabsAndroid:id="@+id/easy_sliding_tabs"Android:layout_width="Match_parent"android:layout_height="Wrap_content"App:easyindicatorcolor="#ff57C1CC"App:easyunderlinecolor="#ffdddddd"App:easytabtextcolor="#ffFF4081"App:easyselectedtagtextcolor="#ff57C1CC"Android:paddingbottom="16DP"android:paddingtop="16DP"/> <android. Support. V4. View. ViewpagerAndroid:id="@+id/easy_vp"Android:layout_width="Match_parent"android:layout_height="0DP"android:layout_weight="1"/></linearlayout>
Fragmentpageradapter
 Public  class tabsfragmentadapter extends fragmentpageradapter implements easyslidingtabs. Tabstitleinterface {    PrivateString[] titles;PrivateList<fragment> fragments; Public Tabsfragmentadapter(Fragmentmanager FM, string[] titles, list<fragment> fragments) {Super(FM); This. fragments = fragments; This. titles = titles; }@Override     PublicSpannablestringGettabtitle(intPosition) {Charsequence title = This. Getpagetitle (position);if(Textutils.isempty (title))return NewSpannablestring (""); Spannablestring spannablestring =NewSpannablestring (title);returnspannablestring; }/** * This method is called by the Viewpager to obtain a title string * to describe the specified page. This method could return null * indicating no title for the This page.     The default implementation returns * NULL.      * * @param Position the position of the title requested * @return A title for the requested page */    @Override     PublicCharsequenceGetpagetitle(intPosition) {if(Position < Titles.length) {returnTitles[position]; }Else{return ""; }    }/** * Return the Fragment associated with a specified position. * * @param Position * *    @Override     PublicFragmentGetItem(intPosition) {Fragment Fragment = This. Fragments.get (position);if(Fragment! =NULL) {return  This. Fragments.get (position); }Else{return NULL; }    }@Override     Public int Gettabdrawablebottom(intPosition) {return 0; }@Override     Public int Gettabdrawableleft(intPosition) {return 0; }@Override     Public int Gettabdrawableright(intPosition) {return 0; }@Override     Public int Gettabdrawabletop(intPosition) {return 0; }/** * Return The number of views available. */    @Override     Public int GetCount() {return  This. Fragments.size (); }}
Easyslidingtabs setting tab background

Bg_easy_sliding_tabs.xml under the easyslidingtabs module :

<selector xmlns:android="Http://schemas.android.com/apk/res/android"  Android:exitfadeduration="@android: Integer/config_shortanimtime">    <item android:state_pressed="true" android:drawable="@color/BG _easy_sliding_tabs_pressed " />    <item android:state_focused="true" android:drawable="@ color/bg_easy_sliding_tabs_pressed " />    <item android:drawable="@android: Color/transparent" /></selector>

Modify the background color in this!!

GitHub Portal

Easyslidingtabs

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

22.Android Very convenient Sliding tab page

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.