Git Product home page Git Product logo

pagerslidingtabstrip-for-xamarin.android's Introduction

Material Pager Sliding Tab Strip for Xamarin.Android

This library has now been deprecated by the new Android Support Design Library. Please see the full component for a sample: https://components.xamarin.com/view/xamandroidsupportdesign

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

This library requires Support v7 AppCompat Version 23

Must set Compile with API 23 in VS or XS

You must add Mono.Android.Export.dll to your References

Build status: Build status

PagerSlidingTabStrip Sample Material

Ported from: https://github.com/jpardogo/PagerSlidingTabStrip

Usage

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

  1. Download the NuGet Package: https://www.nuget.org/packages/Refractored.PagerSlidingTabStrip/

Or add the library as a project.

  1. Include the PagerSlidingTabStrip widget in your layout. This should usually be placed above the ViewPager it represents.

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

  2. In your OnCreate method (or OnCreateView for a fragment), bind the widget to the ViewPager.

    // Initialize the ViewPager and set an adapter
    var pager =  FindViewById<ViewPager>(Resource.Id.pager);
    pager.Adapter = new TestAdapter(SupportFragmentManager);
    
    // Bind the tabs to the ViewPager
    var tabs = FindViewById<PagerSlidingTabStrip>(Resource.Id.tabs);
    tabs.SetViewPager(pager);
    
  3. If your adapter implements the interface CustomTabProvider you can pass your custom tab view/s. In case the view returned contains the id Resource.Id.psts_tab_title, this view should be a TextView and will be used to place the title. If you don't want the library to manage your TextView title for the tab, use a different id than Resource.Id.psts_tab_title in your tab layout.

    If your adapter doesn't impelement the interface CustomTabProvider the default tab will be used (That's a TextView with id Resource.Id.psts_tab_title).

  4. (Optional) If you use implement IOnPageChangeListener with your view pager you should set it in the widget rather than on the pager directly.

    // continued from above
    tabs.SetOnPageChangeListener(pageChangeListener);
    

Customization

From theme:

  • android:textColorPrimary value (from your theme) will be applied automatically to 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 attr:

  • android:textSize Tab text size
  • android:textColor Non selected tabs text color. If you DO define textColor It will be apply to NON selected tabs and NO ALPHA will be applied to them, the colour you define is the one you will see. If you want to define a half transparent color in textColor, you can pass #80FFFFFF (That's an example for half transparent white)
  • android:paddingLeft or android:paddingRight layout padding. If you apply both, they should be balanded.

Custom attr:

  • pstsIndicatorColor Color of the sliding indicator. textPrimaryColor will be it's default color value.
  • pstsUnderlineColor Color of the full-width line on the bottom of the view. textPrimaryColor will be it's default color value.
  • pstsUnderlineHeight Height of the full-width line on the bottom of the view.
  • pstsTextAlpha Set the text alpha transparency for non selected tabs. Range 0..255. 150 is it's default value. It WON'T be use if textColor is defined in the layout. If textColor is NOT defined, It will be applied to the non selected tabs.
  • pstsTextColorSelected Set selected tab text color. textPrimaryColor will be it's default color value.
  • pstsTextStyle Set the text style, default bold.
  • pstsTextSelectedStyle Set the text style of the selected tab, default bold.
  • pstsTextAllCaps If true, all tab titles will be upper case, default true.
  • pstsDividerColor Color of the dividers between tabs. textPrimaryColor will be it's default color value.
  • pstsDividerPadding Top and bottom padding of the dividers.
  • pstsDividerWidth Stroke width of divider line, defaults to 0.
  • pstsIndicatorHeightHeight of the sliding indicator.
  • pstsTabPaddingLeftRight Left and right padding of each tab.
  • pstsScrollOffset Scroll offset of the selected tab.
  • pstsTabBackground Background drawable of each tab, should be a StateListDrawable.
  • pstsShouldExpand If set to true, each tab is given the same weight, default false.
  • pstsPaddingMiddle If true, the tabs start at the middle of the view (Like Newsstand google app).

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

Ported By

Developed By

Credits

License

The MIT License (MIT)

Copyright (c) 2015 James Montemagno / Refractored LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

This is a derivative of Javier Pardo de Santayana Gómez: https://github.com/jpardogo/PagerSlidingTabStrip Which is a derivative of Andreas Stütz: https://github.com/astuetz/PagerSlidingTabStrip

pagerslidingtabstrip-for-xamarin.android's People

Contributors

jamesmontemagno avatar lockeb avatar lpmi-13 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

Watchers

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

pagerslidingtabstrip-for-xamarin.android's Issues

Is it possible to change a single tabs icon?

Hi James,

Excellent work this.

Is it possible to access and change a single tabs icon/color?

Use case:

I have a form made up of multiple tabs and I'd like to indicate to the user when all fields are completed on a tab possibly through a green/red icon.

I do have some idea's but thought I'd check with you before forking.

pstsUnderlineColor not working

Hey James,

I was trying to update the underline color on my application and it does not appear to be working.

See this line app:pstsUnderlineColor="#ffffff" in the axml below.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <com.refractored.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:pstsPaddingMiddle="false"
        app:pstsShouldExpand="true"
        app:pstsUnderlineColor="#ffffff" />
    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>

This is the result:
image

The underline color matches <item name="android:textColorPrimary">@color/wet_asphalt</item> defined in styles.xml.

Additionally I tried

m_PageIndicator = view.FindViewById<PagerSlidingTabStrip>(Resource.Id.tabs);
m_PageIndicator.UnderlineColor = Resource.Color.white;

This also did not work. Any suggestions? Also, per bamboo, happy birthday!

Remove Fragment from Activity, crashing

Hello,

In my activity I have a fragment on the left with a list view (FragmentA) and a fragment on the right which contains a PagerSlidingTabStrip (FragmentB). Depending on the layout, I add them differently. They both add to the layout correctly, and FragmentA can be removed correctly, but when I go to remove the FragmentB, the app crashes and I get a java.lang.reflect.InvocationTargetException. Is there something I need to add in the Fragment to handle being destroyed? Do you have a sample app that shows the SlidingTabs being contained in a fragment themselves?

Thanks in advance

Resource.designer.cs does not contain definition

Hello i have following problem my resource designer doesn't find these dimensions from the PagerSlidingTabStrip Plugin. Im building the project on SDK 23.

global::com.refractored.Resource.Dimension.dialog_fixed_height_major = global::Test.Droid.Resource.Dimension.dialog_fixed_height_major;
            global::com.refractored.Resource.Dimension.dialog_fixed_height_minor = global::Test.Droid.Resource.Dimension.dialog_fixed_height_minor;
            global::com.refractored.Resource.Dimension.dialog_fixed_width_major = global::Test.Droid.Resource.Dimension.dialog_fixed_width_major;
            global::com.refractored.Resource.Dimension.dialog_fixed_width_minor = global::Test.P4V.Droid.Resource.Dimension.dialog_fixed_width_minor;

Compile is set to API 23 and Export.dll is added to Reference.

The sample project from you shows me the exact same error.

i tried to find a solution changed the SDK's but nothing helped.

Best Regards

tab layout

With an AppCompatActivity is possible to make a tablayout without use a custom lib or object as PagerSlindingTabStrip ? Xamarin have a buildin solution ?

Convert to Xamarin.Forms control

I think, with the spread of XamForms, it would be a great idea to make such controls available as an overwritten version of TabbedPage (in this case).

Undefined reference in Resources.cs

Using the latest AppCompat there are 110 undefined references. A fix is to do:

+ global::com.refractored.Resource.Styleable.Theme = global::App.Name.Resource.Styleable.Theme
- global::com.refractored.Resource.Styleable.Theme = global::App.Name.Resource.Styleable.AppCompatTheme

For all instances, every time the Resources.designer.cs is regenerated.

I'm not sure how to go about fixing it in your component however.

Update version on NuGet

The packages hasn't seen an update in over a year, when there is a later version on git. It'd be great if you could update it, thanks.

Missing method Android.Views.ViewTreeObserver::RemoveOnGlobalLayoutListener

I’m getting the following error in our Application,

Missing method Android.Views.ViewTreeObserver::RemoveOnGlobalLayoutListener(ViewTreeObserver/IOnGlobalLayoutListener) in assembly Mono.Android.dll, referenced in assembly /storage/emulated/0/Android/data/blisss.salesnavigator.android/files/.override/Refractored.PagerSlidingTabStrip.dll.

We have a minimal android version of API Level 15 and a target of API level 21 and are using the latest versions of Xamarin Android and the Xamarin support.v4,v13 and v7.appcompat libraries.

The strange thing is that I had it working but after some other changes this error suddenly appeared and I can't seem to get it back in a working condition.

I've tested the code on multiple devices with different api levels and the same error happens on both pre-lollipop and lollipop devices.

App crashes in OnDraw (ObjectDisposedExceptionCannot)

The PagerSlidingTabStrip crashes on a Samsung S7 Edge in the onDraw method.

System.ObjectDisposedExceptionCannot access a disposed object. Object name: 'Android.Graphics.Paint'. Raw Java.Interop.JniPeerMembers.AssertSelf(IJavaPeerable self)<67d9ce838ca8443ba3ee57c49530f12a>:0 Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(string encodedMember, IJavaPeerable self, JniArgumentValue* parameters)<67d9ce838ca8443ba3ee57c49530f12a>:0 Android.Graphics.Paint.set_Color(Color value)<7b54b5e3469b4fb0b2cef44ad5a5b85c>:0 com.refractored.PagerSlidingTabStrip.OnDraw(Canvas canvas)<b1427543c5704ae8bfee8048b832bfc1>:0 Android.Views.View.n_OnDraw_Landroid_graphics_Canvas_(IntPtr jnienv, IntPtr native__this, IntPtr native_canvas)<7b54b5e3469b4fb0b2cef44ad5a5b85c>:0 at (wrapper dynamic-method) System.Object:a757f904-7660-4d22-b077-c7e1696ab4d9 (intptr,intptr,intptr)

Crash when saving. Can't find PutInt

I just upgraded to to 1.0.9 and the app crashes in ActionbarActivity.OnSaveInstanceState.

It looks like Android.OS.BaseBundle is only present on API 21+

04-14 14:19:49.762 W/        (27117): Missing method PutInt in assembly Refractored.PagerSlidingTabStrip.dll, type Android.OS.BaseBundle
04-14 14:19:49.762 W/Mono    (27117): The class Android.OS.BaseBundle could not be loaded, used in Refractored.PagerSlidingTabStrip
Unhandled Exception:

System.TypeLoadException: Could not load type 'Android.OS.BaseBundle' from assembly 'Refractored.PagerSlidingTabStrip'.

Divider not implemented?

This is a great component, thanks for porting it. The code that draws the tab divider is commented out. (PagerSlidingTabStrip.cs, line 627) Is there a reason for this?

Crash on resume on Jelly Bean device

I have a problem that the sample app is crashing after it have been sent to background on my Jelly Bean device. It works on Lollipop.

Steps to reproduce:
Run the sample app
Switch to some other apps
After a while the sample app is put into background
Switch back to the app and it crashes.

It would be nice if some other than me can reproduce this.

text.Text values not showing in the app,,,

Hi James,

I'm not getting the text.Test values sent into the root and shown in the app when I run your project - for some reason. I thought it might be a configuration issue on my system but I did a complete reinstall of all associated Xamarin packages and it's seems to still be there. I've attached a screen shot. If you have any thoughts I'd really appreciate it!
Thank you for this nice project by the way!

Steve
text issue

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.