Coder Social home page Coder Social logo

android-nicetab's Introduction

Android-NiceTab

A nice tab to navigate between the different pages of a ViewPager, supports badge, blur, and cross fade effect.

NiceTab Demo Gif

Usage

For a working implementation of this project see the demo/ folder.

  1. Add the library as a project. or just

    dependencies {
        compile 'me.amiee:nicetab:1.0.0'
    }
  2. Include the NiceTabLayout widget in your layout. This should usually be placed above the ViewPager it represents.

    <me.amiee.nicetab.NiceTabLayout xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="@dimen/tab_height" android:background="?colorPrimary" app:ntlDividerPaddingLeft="8dp" app:ntlDividerPaddingRight="8dp" app:ntlIndicatorHeight="2dp" app:ntlOverlayColor="#aa1a237e" app:ntlTabMode="both" app:ntlTextSize="@dimen/tab_title_text_size" app:ntlTextStyle="normal" app:ntlUnderlineHeight="1dp"/>

  3. In your onCreate method (or onCreateView for a fragment), bind the widget to the ViewPager.

    // Initialize the ViewPager and set an adapter
    mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
    mViewPager.setAdapter(new SampleFragmentPagerAdapter(getChildFragmentManager()));
    
    // Bind the tabs to the ViewPager
    mNiceTabLayout = (NiceTabLayout) view.findViewById(R.id.sliding_tabs);
    mNiceTabLayout.setViewPager(mViewPager);
    
  4. (Optional) If you use an OnPageChangeListener with your view pager you should set it in the widget rather than on the pager directly.

    // continued from above
    mNiceTabLayout.setOnPageChangeListener(mPageChangeListener);
    
  5. (Optional) If your adapter implements the interface NiceTabLayout.IconTabProvider you can add icon to tab view/s. The tab view should be a Textview or ImageView the icon will be used for textView's drawable top or imageView's image.

Customization

    <attr name="ntlTabDistributeEvenly" format="boolean"/>
    <attr name="ntlDrawOrder" format="enum">
        <enum name="indicatorUnderlineDivider" value="0"/>
        <enum name="indicatorDividerUnderline" value="1"/>
        <enum name="underlineIndicatorDivider" value="2"/>
        <enum name="underlineDividerIndicator" value="3"/>
        <enum name="dividerIndicatorUnderline" value="4"/>
        <enum name="dividerUnderlineIndicator" value="5"/>
    </attr>

    <attr name="ntlTabMode" format="enum">
        <!-- Show title only -->
        <enum name="titleOnly" value="0"/>
        <!-- Show icon only(notice: your pager adapter must implements NiceTabLayout.IconProvider) -->
        <enum name="iconOnly" value="1"/>
        <!-- Show both title and icon(notice: your pager adapter must implements NiceTabLayout.IconProvider) -->
        <enum name="both" value="2"/>
    </attr>
    <attr name="ntlTabColorBlendMode" format="enum">
        <enum name="none" value="0"/>
        <!-- Default color and selected color -->
        <enum name="defaultSelected" value="1"/>
        <!-- Selected color and next selected color -->
        <enum name="nextSelected" value="2"/>
    </attr>
    <attr name="ntlTabBackground" format="reference|color"/>
    <attr name="ntlTabOffset" format="dimension"/>
    <attr name="ntlTabSelectedCenter" format="boolean"/>

    <!-- Underline attrs -->
    <attr name="ntlShowUnderline" format="boolean"/>
    <attr name="ntlUnderlineInFront" format="boolean"/>
    <attr name="ntlUnderlineGravity" format="enum">
        <enum name="top" value="0"/>
        <enum name="bottom" value="1"/>
    </attr>
    <attr name="ntlUnderlineColor" format="color"/>
    <attr name="ntlUnderlineHeight" format="dimension"/>
    <attr name="ntlUnderlinePaddingTop" format="dimension"/>
    <attr name="ntlUnderlinePaddingBottom" format="dimension"/>

    <!-- Divider attrs -->
    <attr name="ntlShowDivider" format="boolean"/>
    <attr name="ntlDividerColor" format="color"/>
    <attr name="ntlDividerColors" format="reference"/>
    <attr name="ntlDividerWidth" format="dimension"/>
    <attr name="ntlDividerPadding" format="dimension"/>
    <attr name="ntlDividerPaddingTop" format="dimension"/>
    <attr name="ntlDividerPaddingBottom" format="dimension"/>
    <attr name="ntlDividerPaddingLeft" format="dimension"/>
    <attr name="ntlDividerPaddingRight" format="dimension"/>

    <!-- Indicator attrs -->
    <attr name="ntlShowIndicator" format="boolean"/>
    <attr name="ntlIndicatorGravity" format="enum">
        <enum name="top" value="0"/>
        <enum name="center" value="1"/>
        <enum name="bottom" value="2"/>
    </attr>
    <attr name="ntlIndicatorColor" format="color"/>
    <attr name="ntlIndicatorColors" format="reference"/>
    <attr name="ntlIndicatorHeight" format="dimension"/>
    <attr name="ntlIndicatorCornerRadius" format="dimension"/>
    <attr name="ntlIndicatorPaddingTop" format="dimension"/>
    <attr name="ntlIndicatorPaddingBottom" format="dimension"/>

    <!-- Tab attrs(for title and icon) -->
    <attr name="ntlDefaultTabColor" format="color"/>
    <attr name="ntlDefaultTabColors" format="reference"/>
    <attr name="ntlSelectedTabColor" format="color"/>
    <attr name="ntlSelectedTabColors" format="reference"/>
    <attr name="ntlTabPadding" format="dimension"/>
    <attr name="ntlTabPaddingTop" format="dimension"/>
    <attr name="ntlTabPaddingBottom" format="dimension"/>
    <attr name="ntlTabPaddingLeft" format="dimension"/>
    <attr name="ntlTabPaddingRight" format="dimension"/>
    <attr name="ntlTabViewLayoutId" format="reference"/>
    <attr name="ntlTabViewTextOrImageViewId" format="reference"/>
    <!-- Used when tab shows title and icon -->
    <attr name="ntlDrawablePadding" format="dimension"/>

    <!-- Title text attrs -->
    <attr name="ntlTextSize" format="dimension"/>
    <attr name="ntlTextAllCaps" format="boolean"/>
    <attr name="ntlTextStyle" format="enum">
        <enum name="normal" value="0"/>
        <enum name="bold" value="1"/>
        <enum name="italic" value="2"/>
        <enum name="boldItalic" value="3"/>
    </attr>

    <!-- Icon cross fade effect(only if you set icon drawable with selector(StateListDrawable), this will effect) -->
    <attr name="ntlIconCrossFade" format="boolean"/>
    <!-- If you set icon drawable with selector, set false gives better performance -->
    <attr name="ntlIconTint" format="boolean"/>

    <!-- Blur -->
    <attr name="ntlBlurRadius" format="integer" />
    <attr name="ntlDownSampleFactor" format="integer" />
    <attr name="ntlOverlayColor" format="color" />

    <!-- Badge -->
    <attr name="ntlBadgeGravity" format="enum">
        <enum name="left" value="0"/>
        <enum name="center_left" value="1"/>
        <enum name="center_right" value="2"/>
        <enum name="right" value="3"/>
    </attr>
    <attr name="ntlBadgeTextColor" format="color"/>
    <attr name="ntlBadgeTextSize" format="dimension"/>
    <attr name="ntlBadgeHeight" format="dimension" />
    <attr name="ntlBadgeCornerRadius" format="dimension" />
    <attr name="ntlBadgeMinWidth" format="dimension" />
    <attr name="ntlBadgeMaxWidth" format="dimension" />
    <attr name="ntlBadgeMarginLeft" format="dimension" />
    <attr name="ntlBadgeMarginRight" format="dimension" />
    <attr name="ntlBadgeMarginTop" format="dimension" />
    <attr name="ntlBadgePaddingLeftRight" format="dimension" />
    <attr name="ntlBadgeSmallSize" format="dimension" />
    <attr name="ntlBadgeBackground" format="reference|color"/>

Almost all attributes have their respective setters to change them at runtime , open an issue if you miss any.

Developed By

Credits

License

Copyright 2015 Amiee Robot

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

android-nicetab's People

Contributors

robotamiee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-nicetab's Issues

Cost too much CPU on refresh Draw

Usage in Layout xml:
<me.amiee.nicetab.NiceTabLayout
android:id="@+id/sliding_nice_tabs"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="?colorPrimary"
app:ntlDividerPaddingLeft="8dp"
app:ntlDividerPaddingRight="8dp"
app:ntlIndicatorHeight="2dp"
app:ntlOverlayColor="#aa1a237e"
app:ntlTabMode="titleOnly"
app:ntlTextSize="18sp"
app:ntlTextStyle="normal"
app:ntlUnderlineHeight="1dp"
/>

Detect by memory working history, as attached

support for layout direction

I am using this very good library, but the problem I am facing now is that, I am using an Arabic interface, and I am getting an LTR direction in the tabs, instead of the RTL.

How update badge into tab when receiver data from server

java.lang.NullPointerException
at com.dreamm.Milispace.view.slidingtab.StartNiceTab.clearBadge(StartNiceTab.java:177)
at com.dreamm.Milispace.view.slidingtab.StartNiceTab.setBadge(StartNiceTab.java:160)

public void setBadgeActivity(int badgeInbox) {
    clearBadge();
    if (badgeInbox > 0) {
        mNiceTabLayout.setBadge(2, String.valueOf(badgeInbox));
    }
}

private void clearBadge() {
    mNiceTabLayout.clearBadge();
}

public void setBadge(int badgeInbox, int badgeActivity) {
clearBadge();
if (badgeInbox > 0) {
mNiceTabLayout.setBadge(2, String.valueOf(badgeInbox));
}
if (badgeActivity > 0) {
mNiceTabLayout.setBadge(3, String.valueOf(badgeActivity));
}
}

SelectedTabColor is not changing color in Android 4.3

Hi,
I'm Testing my app in a Galaxy Nexus (Android 4.3) version and in a Nexus 5 (Android 5.1.1).
Everything is fine in the Nexus 5, but in the Galaxy Nexus the tabs didn't change color when the Pages changes, when the tab is clicked it changes, but the last selected tab didn't, if i click in all the tabs all will stay with the color selected.

I have to do something special so it can work int the old version?

<me.amiee.nicetab.NiceTabLayout android:id="@+id/main_tabs_slide" android:layout_width="match_parent" android:layout_height="48dp" android:layout_alignParentBottom="true" android:background="#F8F8F8" app:ntlTabDistributeEvenly="true" app:ntlDefaultTabColor="#B2B2B2" app:ntlDividerPaddingLeft="6dp" app:ntlDividerPaddingRight="6dp" app:ntlSelectedTabColor="?colorPrimary" app:ntlShowIndicator="false" app:ntlShowUnderline="true" app:ntlTabMode="iconOnly" />

If i change to app:ntlTabMode="both" it works again.

Thanks

Binary XML file line #9: Error inflating class me.amiee.nicetab.NiceTabLayout

Process: com.example.milispace.milispace, PID: 13101
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.milispace.milispace/com.dreamm.Milispace.view.slidemenu.MilispaceSlideMenu}: android.view.InflateException: Binary XML file line #9: Error inflating class me.amiee.nicetab.NiceTabLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2525)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2617)
at android.app.ActivityThread.access$800(ActivityThread.java:182)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:218)
at android.app.ActivityThread.main(ActivityThread.java:5657)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:990)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:785)
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class me.amiee.nicetab.NiceTabLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.dreamm.Milispace.view.slidingtab.StartNiceTab.onCreateView(StartNiceTab.java:46)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:602)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1244)
at android.app.Activity.performStart(Activity.java:6151)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2482)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2617) 
at android.app.ActivityThread.access$800(ActivityThread.java:182) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:218) 
at android.app.ActivityThread.main(ActivityThread.java:5657) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:990) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:785) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at com.dreamm.Milispace.view.slidingtab.StartNiceTab.onCreateView(StartNiceTab.java:46) 
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) 
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) 
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) 
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339) 
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:602) 
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1244) 
at android.app.Activity.performStart(Activity.java:6151) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2482) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2617) 
at android.app.ActivityThread.access$800(ActivityThread.java:182) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:218) 
at android.app.ActivityThread.main(ActivityThread.java:5657) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:990) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:785) 
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v8/renderscript/RenderScript;
at me.amiee.nicetab.NiceTabStrip.initRenderScript(NiceTabStrip.java:544)
at me.amiee.nicetab.NiceTabStrip.(NiceTabStrip.java:502)
at me.amiee.nicetab.NiceTabLayout.(NiceTabLayout.java:194)
at me.amiee.nicetab.NiceTabLayout.(NiceTabLayout.java:133)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at com.dreamm.Milispace.view.slidingtab.StartNiceTab.onCreateView(StartNiceTab.java:46) 
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) 
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) 
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) 
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339) 
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:602) 
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1244) 
at android.app.Activity.performStart(Activity.java:6151) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2482) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2617) 
at android.app.ActivityThread.access$800(ActivityThread.java:182) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:218) 
at android.app.ActivityThread.main(ActivityThread.java:5657) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:990) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:785) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v8.renderscript.RenderScript" on path: DexPathList[[dex file "/data/data/com.example.milispace.milispace/files/instant-run/dex/slice-zip4j-1.3.2_f728f80ccf711e45ce184a9c1b90868a8c287ed9-classes.dex", dex file "/data/data/com.example.milispace.milispace/files/instant-run/dex/slice-universal-image-loader-1.9.3_c0a769fce08f3876d58b638cd3cf59c11e0d5448-classes.dex", dex file "/data/data/com.example.milispace.milispace/files/instant-run/dex/slice-systembartint-1.0.3_79084032bdf4831b4792a45df467e6d485629218-classes.dex", dex file "/data/data/com.example.milispace.milispace/files/instant-run/dex/slice-support-annotations-23.3.0_5f3c49fb8cf92a86f170212d7084646ffc9e0982-classes.dex", dex file "/data/data/com.example.milispace.milispace/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.example.milispace.milispace

Tabs text font

Hello,
can I change the tab text fonts?
and if so, then how?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.