An interactive indicator to navigate between the different pages of a ViewPager

Overview

Android PagerSlidingTabStrip (default Material Design)

This library is not maintained anymore and there will be no further releases. For most of the cases you can use TabLayout instead of this library.

Interactive paging indicator widget, compatible with the ViewPager from the Android Support Library.

PagerSlidingTabStrip Sample Material ------ PagerSlidingTabStrip Sample Material

Usage

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

  1. Include the following dependency in your build.gradle file.
compile 'com.jpardogo.materialtabstrip:library:1.1.1'

Or add the library as a project. I tried to send a pull request, but looks like the original developer doesn't maintain it anymore.

  1. Include the PagerSlidingTabStrip widget in your layout. This should usually be placed above the ViewPager it represents.
<com.astuetz.PagerSlidingTabStrip
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary" />
  1. In your onCreate method (or onCreateView for a fragment), bind the widget to the ViewPager:
// Initialize the ViewPager and set an adapter
ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(new TestAdapter(getSupportFragmentManager()));

// Bind the tabs to the ViewPager
PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
tabs.setViewPager(pager);

That's all you need to do, but if you want to use your own tabs, then...

  1. If your adapter implements the interface CustomTabProvider you can paste your custom tab view/s.

    • In case the the view returned contains the id R.id.psts_tab_title, this view should be a TextView and will be used to placed the title and set the view state (pressed/selected/default).

    • If you don't want the library manage your TextView title for the tab, use a different id than R.id.psts_tab_title in your tab layout.

    • The interface provide callbacks for selection and unselection of tabs as well.

    • If your adapter doesn't implement the interface CustomTabProvider the default tab will be used, which is a TextView with id R.id.psts_tab_title).

  2. (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
tabs.setOnPageChangeListener(mPageChangeListener);

Customization

From theme:

  • android:textColorPrimary value (from your theme) will be applied automatically to the tab's text color (Selected tab with 255 alpha and non selected tabs with 150 alpha), underlineColor, dividerColor and indicatorColor, if the values are not defined on the xml layout.

Notes about some of the native attributes:

  • android:paddingLeft or android:paddingRight layout padding. If you apply both, they should be balanced. Check issue #69 for more information.

Custom attributes:

  • pstsIndicatorColor Color of the sliding indicator. textColorPrimary will be it's default color value.
  • pstsIndicatorHeightHeight of the sliding indicator.
  • pstsUnderlineColor Color of the full-width line on the bottom of the view. textColorPrimary will be it's default color value.
  • pstsUnderlineHeight Height of the full-width line on the bottom of the view.
  • pstsDividerColor Color of the dividers between tabs. textColorPrimary will be it's default color value.
  • pstsDividerWidth Stroke width of divider line, defaults to 0.
  • pstsDividerPadding Top and bottom padding of the dividers.
  • pstsShouldExpand If set to true, each tab is given the same weight, default false.
  • pstsScrollOffset Scroll offset of the selected tab.
  • pstsPaddingMiddle If true, the tabs start at the middle of the view (Like Newsstand google app).
  • pstsTabPaddingLeftRight Left and right padding of each tab.
  • pstsTabBackground Background drawable of each tab, should be a StateListDrawable.
  • pstsTabTextSize Tab text size (sp).
  • pstsTabTextColor Tab text color that can either be a color (text color won't changed) or a selector with a color per state: pressed (tab pressed), selected (tab active), default (active non active). The order of states in the selector is important. Check issue #68 for more information.
  • pstsTabTextStyle Set the text style, default normal on API 21, bold on older APIs.
  • pstsTabTextAllCaps If true, all tab titles will be upper case, default true.
  • pstsTabTextAlpha Set the text alpha transparency for non selected tabs. Range 0..255. 150 is it's default value. It WON'T be used if pstsTabTextColor is defined in the layout. If pstsTabTextColor is NOT defined, It will be applied to the non selected tabs.
  • pstsTabTextFontFamily Set the font family name. Default sans-serif-medium on API 21, sans-serif on older APIs.

Almost all attributes have their respective getters and setters to change them at runtime. To change dynamically pstsTabTextFontFamily and pstsTabTextStyle you can call:

  • public void setTypeface(Typeface typeface, int style). It can be used to define custom fonts in default tabs. Otherwise you can use custom tabs with CustomTabProvider.

Please open an issue if you find any are missing.

Developed By

Contributions

  • Please, read the README file before opening an issue, thanks.
  • Please, all the Pull Request must be sent to the dev branch, thanks..

Credits

License

Copyright 2013 Andreas Stuetz

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.
Comments
  • Middle Alignment (pstsPaddingMiddle=

    Middle Alignment (pstsPaddingMiddle="true") only shows first tab. Everything else is hidden

    Only the first tab appears. I am able to scroll to all the other ones but they don't show up or scroll. There are no build errors of any kind. The following does appear in the preview box, however:

    java.lang.NumberFormatException: Color value '/Users/charrondev/Dev/android-sdk/platforms/android-21/data/res/color/primary_text_dark.xml' must start with # at com.android.layoutlib.bridge.impl.ResourceHelper.getColor(ResourceHelper.java:72) at android.content.res.BridgeResources.getColor(BridgeResources.java:182) at com.astuetz.PagerSlidingTabStrip.(PagerSlidingTabStrip.java:142) at com.astuetz.PagerSlidingTabStrip.(PagerSlidingTabStrip.java:129) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:379) at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:99) at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:172) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207) at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64) at android.view.LayoutInflater.rInflate(LayoutInflater.java:782) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:385) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:401) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:329) at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:333) at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:674) at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:663) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932) at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:663) at com.android.tools.idea.rendering.RenderService.render(RenderService.java:790) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:611) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1900(AndroidLayoutPreviewToolWindowManager.java:81) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:553) at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178) at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212) at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:548) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310) at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227) at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217) at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238) at com.intellij.util.Alarm$Request$1.run(Alarm.java:327) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:695)

    This is on the latest Android SDK and build tools.

    opened by charrondev 30
  • java.lang.NoSuchFieldError: com.astuetz.pagerslidingtabstrip.R$id.tab_title

    java.lang.NoSuchFieldError: com.astuetz.pagerslidingtabstrip.R$id.tab_title

    could you please explain to me this error? This doesn't happen when I add an textView with tab_title id, docs don't mention to add it although, and still I get other issue, the view is blank...

    java.lang.NoSuchFieldError: com.astuetz.pagerslidingtabstrip.R$id.tab_title
                at com.astuetz.PagerSlidingTabStrip.addTab(PagerSlidingTabStrip.java:279)
                at com.astuetz.PagerSlidingTabStrip.notifyDataSetChanged(PagerSlidingTabStrip.java:253)
                at com.astuetz.PagerSlidingTabStrip.setViewPager(PagerSlidingTabStrip.java:236)
    
    question 
    opened by younes0 24
  • Style from `CustomTabProvider` is overwritten

    Style from `CustomTabProvider` is overwritten

    I am trying to have a single tab with a different text color. For this, I implement CustomTabProvider and call TextView.setTextColor().

    However, this change is overwritten by updateTabStyles().

    I suggest to change the code so, that the tab style is only applied by the library if CustomTabProvider is not implemented. (I will probably make a pull request for this myself).

    bug 
    opened by Nutomic 21
  • No padding around text.

    No padding around text.

    There is no padding around text of tabs with version 4.0.4 on a tablet. It works on my Nexus 5 on Lollipop. Here is my XML extract : <com.astuetz.PagerSlidingTabStrip android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" android:textColor="@color/white" app:pstsIndicatorColor="@color/white" app:pstsTabBackground="?attr/selectableItemBackground"/>

    https://github.com/StephaneBg/ScoreItProject/blob/master/ScoreIt/src/main/res/layout-sw600dp/activity_about.xml

    screenshot_2014-11-25-18-20-55

    screenshot_2014-11-25-18-24-56 1

    opened by StephaneBg 16
  • Performance Issues

    Performance Issues

    For some reason this implementation is very very laggy in comparison with original astuetz/PagerSlidingTabStrip. Following setup will reproduce the issue:

    1. Main activity layout is DrawerLayout with Fragments being loaded to the ViewPager's manager
    2. Add more than 5 pages to the pager
    3. Each fragment has ScrollView as the root element and couple more views inside (ex. create a simple View with 500dp height)

    Swiping and scrolling loses frames, which is not the case when using original lib.

    bug 
    opened by VitalikL 12
  • Support Indicator Padding

    Support Indicator Padding

    It would be nice to support padding on the sliding tab indicator. Here are a few examples.

    Google Example(Play Games App):

    See the "Featured" tab here:

    Non Google Example:

    See the "Root" tab here:

    opened by jaredsburrows 10
  • Remove selected text color attribute

    Remove selected text color attribute

    This removes the custom attribute for tab text color selected, replacing it with the standard behaviour of android:textColor.


    Default case, with no textColor specified:

    <com.astuetz.PagerSlidingTabStrip
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:pstsPaddingMiddle="true" />
    

    default_no_color_specified


    Expected best case, with textColor specified with a custom color state list resource:

    <com.astuetz.PagerSlidingTabStrip
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:textColor="@color/my_custom_tab_color_state_list"
            app:pstsPaddingMiddle="true" />
    

    color_state_list_specified


    Case with textColor specified with a color resource that's just a single color:

    <com.astuetz.PagerSlidingTabStrip
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:textColor="@android:color/holo_green_light"
            app:pstsPaddingMiddle="true" />
    

    single_color_resource_specified


    Case with textColor specified with a hex value:

    <com.astuetz.PagerSlidingTabStrip
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:textColor="#ef23f1"
            app:pstsPaddingMiddle="true" />
    

    single_hex_color_specified

    opened by ataulm 9
  • crashes when close app

    crashes when close app

    12-11 10:25:22.940 10693-10693/com.alex.photolessons E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.alex.photolessons, PID: 10693 java.lang.IllegalStateException: Observer com.astuetz.PagerSlidingTabStrip$PagerAdapterObserver@3b31bb43 was not registered. at android.database.Observable.unregisterObserver(Observable.java:69) at android.support.v4.view.PagerAdapter.unregisterDataSetObserver(PagerAdapter.java:294) at com.astuetz.PagerSlidingTabStrip.onDetachedFromWindow(PagerSlidingTabStrip.java:533) at android.view.View.dispatchDetachedFromWindow(View.java:13441) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2837) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2834) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2834) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2834) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2834) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2834) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2834) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2834) at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:2889) at android.view.ViewRootImpl.doDie(ViewRootImpl.java:5390) at android.view.ViewRootImpl.die(ViewRootImpl.java:5367) at android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:359) at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:314) at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:84) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3707) at android.app.ActivityThread.access$1400(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1332) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) 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:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

    opened by almaz010891 9
  • How to set Underline under Indicator

    How to set Underline under Indicator

    Hello man Thanks for this wonderful project! I have 2 questions. I will try to explain it with pictures.

    Thats what I want to make tabs0

    Thats what I have now picture_1

    My question. How to make as in first picture when Underline under Indicator.

    My second question is is it possible here to add shadows under the tabs?

    question 
    opened by nurzhannogerbek 8
  • Problem maintaining tab highlight upon orientation change

    Problem maintaining tab highlight upon orientation change

    I'm experiencing a slightly strange issue, and for whatever reason it only occurs on my Nexus 5, but not on my Nexus 9. It's kind of hard to describe, so I'll start with some screenshots.

    This is what the application looks like to begin with:

    device-2014-12-01-001835

    As you can see, there are a number of tabs, starting with "All movies", "Favorites" and "New releases". Whenever I swipe to a tab that's not the first tab, it messes up the highlighting upon orientation change.

    Here's an example, starting with the "New releases" tab selected:

    device-2014-12-01-001919

    Rotate the device, and this is what it looks like:

    device-2014-12-01-001944

    As you can see, it doesn't look right. Here's a screenshot of what it looks like when I scroll the tabs a bit:

    device-2014-12-01-001956

    Once I start scrolling the actual content, it fixes itself immediately:

    device-2014-12-01-002006

    bug 
    opened by MizzleDK 8
  • underline changes position, but white text not change position

    underline changes position, but white text not change position

    When mViewPager.setCurrentItem(position) underline changes position, but white text not change position screenshot here: http://hkar.ru/x5vd Sorry for my English.

    bug 
    opened by almaz010891 7
  • Update README with pointers for TabLayout

    Update README with pointers for TabLayout

    Atop the README it says:

    This library is not maintained anymore and there will be no further releases. For most of the cases you can use TabLayout instead of this library.

    After a significant amount of searching through the internet it is still not clear to me how TabLayout can successfully be used to implement a tab strip where the selected tab stays in the center. Thus, a quick link below this statement, or a brief suggestion of what methods/attributes to look into for TabLayout would be very useful.

    opened by pallgeuer 1
  • when i tried to access, it shows like this.

    when i tried to access, it shows like this.

    Error:Cannot choose between the following configurations of project :library:

    • debugApiElements
    • debugRuntimeElements
    • releaseApiElements
    • releaseRuntimeElements All of them match the consumer attributes:
    • Configuration 'debugApiElements':
      • Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
      • Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      • Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
      • Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
    • Configuration 'debugRuntimeElements':
      • Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
      • Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      • Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
      • Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.
    • Configuration 'releaseApiElements':
      • Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
      • Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      • Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
      • Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
    • Configuration 'releaseRuntimeElements':
      • Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
      • Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      • Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
      • Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.
    opened by 6rkmac 0
  • null object reference

    null object reference

    hi. I'm building new project by sample project but I have an error that can not solve it.

    MainActivity: ` package com.example.alireza.myapplication;

    import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.TransitionDrawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.content.ContextCompat; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Toast;

    import com.astuetz.PagerSlidingTabStrip; import com.readystatesoftware.systembartint.SystemBarTintManager;

    import butterknife.BindView; import butterknife.ButterKnife;

    public class MainActivity extends ActionBarActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tabs)
    PagerSlidingTabStrip tabs;
    @BindView(R.id.pager)
    ViewPager pager;
    
    private MyPagerAdapter adapter;
    private Drawable oldBackground = null;
    private int currentColor;
    private SystemBarTintManager mTintManager;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        setSupportActionBar(toolbar);
        // create our manager instance after the content view is set
        mTintManager = new SystemBarTintManager(this);
        // enable status bar tint
        mTintManager.setStatusBarTintEnabled(true);
        adapter = new MyPagerAdapter(getSupportFragmentManager());
    
        pager.setAdapter(adapter);
        tabs.setViewPager(pager);
        final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources()
                .getDisplayMetrics());
        pager.setPageMargin(pageMargin);
        pager.setCurrentItem(1);
        changeColor(ContextCompat.getColor(getBaseContext(), R.color.green));
    
        tabs.setOnTabReselectedListener(new PagerSlidingTabStrip.OnTabReselectedListener() {
            @Override
            public void onTabReselected(int position) {
                Toast.makeText(MainActivity.this, "Tab reselected: " + position, Toast.LENGTH_SHORT).show();
            }
        });
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_contact:
                QuickContactFragment.newInstance().show(getSupportFragmentManager(), "QuickContactFragment");
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    private void changeColor(int newColor) {
        tabs.setBackgroundColor(newColor);
        mTintManager.setTintColor(newColor);
        // change ActionBar color just if an ActionBar is available
        Drawable colorDrawable = new ColorDrawable(newColor);
        Drawable bottomDrawable = new ColorDrawable(ContextCompat.getColor(getBaseContext(), android.R.color.transparent));
        LayerDrawable ld = new LayerDrawable(new Drawable[]{colorDrawable, bottomDrawable});
        if (oldBackground == null) {
            getSupportActionBar().setBackgroundDrawable(ld);
        } else {
            TransitionDrawable td = new TransitionDrawable(new Drawable[]{oldBackground, ld});
            getSupportActionBar().setBackgroundDrawable(td);
            td.startTransition(200);
        }
    
        oldBackground = ld;
        currentColor = newColor;
    }
    
    public void onColorClicked(View v) {
        int color = Color.parseColor(v.getTag().toString());
        changeColor(color);
    }
    
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt("currentColor", currentColor);
    }
    
    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        currentColor = savedInstanceState.getInt("currentColor");
        changeColor(currentColor);
    }
    
    public class MyPagerAdapter extends FragmentPagerAdapter {
    
        private final String[] TITLES = {"Categories", "Home", "Top Paid", "Top Free", "Top Grossing", "Top New Paid",
                "Top New Free", "Trending"};
    
        MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }
    
        @Override
        public CharSequence getPageTitle(int position) {
            return TITLES[position];
        }
    
        @Override
        public int getCount() {
            return TITLES.length;
        }
    
        @Override
        public Fragment getItem(int position) {
            return SuperAwesomeCardFragment.newInstance(position);
        }
    }
    

    }`

    my error message:

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.alireza.myapplication/com.example.alireza.myapplication.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.view.ViewPager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2434) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) at android.app.ActivityThread.access$900(ActivityThread.java:157) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5551) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.view.ViewPager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference at com.example.alireza.myapplication.MainActivity.onCreate(MainActivity.java:69) at android.app.Activity.performCreate(Activity.java:6272) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) at android.app.ActivityThread.access$900(ActivityThread.java:157) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5551)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 

    opened by spydermard 0
Owner
JPARDOGO
Android language writer and translator. Twitter: @jpardogo
JPARDOGO
Android auto scroll viewpager or viewpager in viewpager

Android Auto Scroll ViewPager ViewPager which can auto scrolling, cycling, decelerating. ViewPager which can be slided normal in parent ViewPager. Att

Trinea 1.7k Dec 10, 2022
Combine ViewPager and Animations to provide a simple way to create applications' guide pages.

WoWoViewPager WoWoViewPager combines ViewPager and Animations to provide a simple way to create applications' guide pages. When users are dragging WoW

黄伟平 2.7k Dec 30, 2022
Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

Android ViewPagerIndicator Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability

Jake Wharton 10.2k Jan 3, 2023
Android - A ViewPager page indicator that displays the current page number and (optionally) the page count

NumericPageIndicator A ViewPager page indicator that displays the current page number and (optionally) the page count. It can also display buttons to

Manuel Peinado Gallego 253 Nov 16, 2022
Pager (especially for ViewPager) indicator in two styles: circle & fraction.

PagerIndicator Pager (especially for ViewPager) indicator in two styles: circle & fraction. Demo circle fraction Dependency implementation 'me.liangfe

Fei Liang 212 Nov 28, 2022
Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

Android ViewPagerIndicator Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability

Jake Wharton 10.2k Jan 5, 2023
Pager (especially for ViewPager) indicator in two styles: circle & fraction.

PagerIndicator Pager (especially for ViewPager) indicator in two styles: circle & fraction. Demo circle fraction Dependency implementation 'me.liangfe

Fei Liang 212 Nov 28, 2022
UltraViewPager is an extension for ViewPager to provide multiple features in a single ViewPager.

UltraViewPager 中文文档 ProjectUltraViewPager is a ViewPager extension that encapsulates multiple features, mainly to provide a unified solution for multi

Alibaba 5k Dec 20, 2022
Don't write a ViewPager Adapter! Hook up your ViewPager to your data model using Android Data Binding Framework. With Kotlin support!

Don't write a ViewPager Adapter! Hook up your ViewPager to your data model using Android Data Binding Framework. Show some ❤️ ?? Sweet and short libra

Rakshak R.Hegde 180 Nov 18, 2022
Persons cards list viewpager - Persons cards list viewpager using kotlin

persons_cards_list_viewpager Дизайн и условие взяты из https://github.com/appKOD

Mironov Ury 1 Mar 1, 2022
A Page Indicator Lib is realized in a different way.

#FlycoPageIndicator A Page Indicator Lib is realized in a different way. Support for Android 2.2 and up. ##Demo ####Here is a DemoApk download ##Gradl

Flyco 537 Dec 17, 2022
A different beautiful ViewPager, with quick swipe controls

HollyViewPager Usage Add a HollyViewPager in your layout <com.github.florent37.hollyviewpager.HollyViewPager android:id="@+id/hollyViewPager"

Florent CHAMPIGNY 1.1k Dec 9, 2022
A lightweight indicator like in nexus 5 launcher

CircleIndicator A lightweight indicator like in nexus 5 launcher Gradle AndroidX dependencies { implementation 'me.relex:circleindicator:2.1.6' }

relex 4.1k Jan 5, 2023
A spring indicator like Morning Routine guide.

SpringIndicator An indicator like Morning Routine guide.It was originally based on BezierDemo. The sample app: click me #Usage Add the dependency to y

null 2.4k Feb 21, 2022
A rubber indicator

RubberIndicator A rubber indicator for ViewPager Designed by Valentyn Khenkin Here is the CSS version Usage The attributes for RubberIndicator are not

Fei Liang 1.6k Dec 16, 2022
Library containing common animations needed for transforming ViewPager scrolling for Android v13+.

ViewPagerTransforms Library containing common animations needed for transforming ViewPager scrolling on Android v13+. This library is a rewrite of the

Ian Thomas 2.5k Dec 31, 2022
A custom ViewPager title strip which gives continuous feedback to the user when scrolling

SmartTabLayout A custom ViewPager title strip which gives continuous feedback to the user when scrolling. This library has been added some features an

ogaclejapan 7k Jan 1, 2023
A Material Design ViewPager easy to use library

MaterialViewPager Material Design ViewPager easy to use library Sample And have a look on a sample Youtube Video : Youtube Link Download In your modul

Florent CHAMPIGNY 8.2k Dec 29, 2022
An android ViewPager extension allowing infinite scrolling

NO LONGER MAINTAINED LoopingViewPager An android ViewPager extension allowing infinite scrolling. You can use it with "standart" PagerAdapter (inflati

Leszek Mzyk 992 Nov 10, 2022