Giter Site home page Giter Site logo

jagaric / un-material-tab Goto Github PK

View Code? Open in Web Editor NEW

This project forked from creageek/un-material-tab

0.0 2.0 0.0 10.22 MB

Custom tab layout which can be used as a material TabLayout alternative and consists basic functionality which Google's TabLayout has.

License: Apache License 2.0

Java 8.25% Kotlin 91.75%

un-material-tab's Introduction

#un-material-tab library A customizable alternative of TabLayout from Support Design library which provides almost the same functionality.

##How to add? I. In your build.gradle file add the following dependency:

dependencies {
    compile 'com.ruslankishai:unmaterialtabs:0.1a'
}

II. Declare RoundTabLayout inside your layout.xml file:

<com.ruslankishai.unmaterialtab.tabs.RoundTabLayout
            android:id="@+id/round_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            app:accent="@color/colorAccent" />

III. Declare RoundTabLayout with ViewPager in your Java class:

ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);

//set adapter to your ViewPager
ViewPager.setAdapter(new TabPagerAdapter(getFragmentManager()));

RoundTabLayout tabLayout = (RoundTabLayout) findViewById(R.id.roundTabLayout);
tabLayout.setupWithViewPager(viewPager);

IV. Override you getPageTitle method in your ViewPager’s adapter to return tab title.

@Override
public CharSequence getPageTitle(int position) {  
     switch (position) {
          case 0:
               return "First item";
          ...
     }
}

##How to customize? I. In your layout.xml file you can set a few attributes to RoundedTabLayout:

  • android:background
    • This attribute works just like usual background attribute (reference to a color).
  • app:accent
    • This attribute allows you to set accent color for tab selection, stroke and text (reference to a color).
  • app:cornerRadius
    • This attribute sets the tab corner radius. Possible values are:
      • circle (default)
      • rounded
      • rectangle
      • value in px from 0 to 50

II. In your class.java you can set some values to customize specific tab:

  • Use RoundTab#setIcon method to change icon. You can get RoundTab object via RoundTabLayout#getTab method which accept tab index as parameter. To enable tab icon, you should also use RoundTab#setHasIcon.
//after initializing RoundTabLayout and ViewPager
RoundTab tab = tabLayout.getTab(0);
Drawable icon = getResources().getDrawable(R.drawable.globe);
tab.setIcon(icon);
//enable icon in current tab
tab.setHasIcon(true);

//repeat this code for another tabs
  • To disable tab stroke use RoundTab#setHasStroke method.
//after initializing RoundTabLayout and ViewPager
RoundTab tab = tabLayout.getTab(0);
tab.setHasStroke(true);
…
  • To change corners radius use RoundTab#setCornerRadius which accept values from 0 to 50 as a parameter.
//after initializing RoundTabLayout and ViewPager
RoundTab tab = tabLayout.getTab(0);
tab.setCornerRadius(35);
…
  • To change tab text use RoundTab#setText which accept String as a parameter.
//after initializing RoundTabLayout and ViewPager
RoundTab tab = tabLayout.getTab(0);
tab.setText(“Usage example”);
…

##Where is un-material-tab demo app? The app works just as an example of usage with different options. Will be uploaded to Play Store sooner.

<img src="https://github.com/creageek/un-material-tabs/blob/master/resources/custom_tab.gif" width="360"_tab>

##What about contributions? This is my first public repo and first library so I’m trying to keep this code as much clean and well-commented as I can. Feel free to contribute :)

##License

Copyright (C) 2017 Ruslan Kishai

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.

un-material-tab's People

Contributors

creageek avatar

Watchers

James Cloos avatar  avatar

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.