{"id":7979,"date":"2015-11-14T08:50:54","date_gmt":"2015-11-14T08:50:54","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/14\/sliding-tabs-in-toolbar-using-material-design-open-source-projects-angular-material\/"},"modified":"2015-11-14T08:50:54","modified_gmt":"2015-11-14T08:50:54","slug":"sliding-tabs-in-toolbar-using-material-design-open-source-projects-angular-material","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/14\/sliding-tabs-in-toolbar-using-material-design-open-source-projects-angular-material\/","title":{"rendered":"Sliding Tabs in Toolbar using Material Design-open source projects angular\/material"},"content":{"rendered":"<p>As i already wrote you can find an example here: http:\/\/www.android4devs.com\/2015\/01\/how-to-make-material-design-sliding-tabs.html<\/p>\n<p>By the way, what you need to is include in your project this code: https:\/\/developer.android.com\/samples\/SlidingTabsColors\/src\/com.example.android.common\/view\/SlidingTabLayout.html. So create a class in which you will paste the entire code.<\/p>\n<p>Then create your activity that extends <code>ActionBarActivity<\/code> like for example this one:<\/p>\n<pre><code>public class MainActivity extends ActionBarActivity {\n\nstatic final String LOG_TAG = \"SlidingTabsBasicFragment\";\nprivate SlidingTabLayout mSlidingTabLayout;\nprivate ViewPager mViewPager;\n\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.fragment_sample);\n    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);\n\n    mViewPager = (ViewPager) findViewById(R.id.viewpager);\n    mViewPager.setAdapter(new SamplePagerAdapter());\n    mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);\n    mSlidingTabLayout.setViewPager(mViewPager);\n\n    \/*\n     * FragmentTransaction transaction =\n     * getSupportFragmentManager().beginTransaction();\n     * SlidingTabsBasicFragment fragment = new SlidingTabsBasicFragment();\n     * transaction.replace(R.id.sample_content_fragment, fragment);\n     * transaction.commit();\n     *\/\n\n}\n\n@Override\npublic boolean onCreateOptionsMenu(Menu menu) {\n    \/\/ Inflate the menu; this adds items to the action bar if it is present.\n    getMenuInflater().inflate(R.menu.main, menu);\n    return true;\n}\n\n@Override\npublic boolean onOptionsItemSelected(MenuItem item) {\n    \/\/ Handle action bar item clicks here. The action bar will\n    \/\/ automatically handle clicks on the Home\/Up button, so long\n    \/\/ as you specify a parent activity in AndroidManifest.xml.\n    int id = item.getItemId();\n    if (id == R.id.action_settings) {\n        return true;\n    }\n    return super.onOptionsItemSelected(item);\n}\n\nclass SamplePagerAdapter extends PagerAdapter {\n\n    \/**\n     * @return the number of pages to display\n     *\/\n    @Override\n    public int getCount() {\n        return 5;\n    }\n\n    \/**\n     * @return true if the value returned from\n     *         {@link #instantiateItem(ViewGroup, int)} is the same object\n     *         as the {@link View} added to the {@link ViewPager}.\n     *\/\n    @Override\n    public boolean isViewFromObject(View view, Object o) {\n        return o == view;\n    }\n\n    \/\/ BEGIN_INCLUDE (pageradapter_getpagetitle)\n    \/**\n     * Return the title of the item at {@code position}. This is important\n     * as what this method returns is what is displayed in the\n     * {@link SlidingTabLayout}.\n     * <br \/>\n     * Here we construct one using the position value, but for real\n     * application the title should refer to the item's contents.\n     *\/\n    @Override\n    public CharSequence getPageTitle(int position) {\n        return \"Item \" + (position + 1);\n    }\n\n    \/\/ END_INCLUDE (pageradapter_getpagetitle)\n\n    \/**\n     * Instantiate the {@link View} which should be displayed at\n     * {@code position}. Here we inflate a layout from the apps resources\n     * and then change the text view to signify the position.\n     *\/\n    @Override\n    public Object instantiateItem(ViewGroup container, int position) {\n        \/\/ Inflate a new layout from our resources\n\n        View view = getLayoutInflater().inflate(R.layout.pager_item,\n                container, false);\n        \/\/ Add the newly created View to the ViewPager\n        container.addView(view);\n\n        \/\/ Retrieve a TextView from the inflated View, and update it's text\n        TextView title = (TextView) view.findViewById(R.id.item_title);\n        title.setText(String.valueOf(position + 1));\n\n        Log.i(LOG_TAG, \"instantiateItem() [position: \" + position + \"]\");\n\n        \/\/ Return the View\n        return view;\n    }\n\n    \/**\n     * Destroy the item from the {@link ViewPager}. In our case this is\n     * simply removing the {@link View}.\n     *\/\n    @Override\n    public void destroyItem(ViewGroup container, int position, Object object) {\n        container.removeView((View) object);\n        Log.i(LOG_TAG, \"destroyItem() [position: \" + position + \"]\");\n    }\n\n}\n<\/code><\/pre>\n<p>of course this fragment layout:<\/p>\n<pre><code>\n\n\n    \n\n        \n\n            \n        \n    \n\n    \n\n\n<\/code><\/pre>\n<p>and the pager_item.xml<\/p>\n<pre><code>\n\n\n\n    \n\n    \n\n\n<\/code><\/pre>\n<p>This is the way to do it.<\/p>\n<p>You can also use this library: https:\/\/github.com\/florent37\/MaterialViewPager or this one: https:\/\/android-arsenal.com\/details\/1\/1100<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As i already wrote you can find an example here: http:\/\/www.android4devs.com\/2015\/01\/how-to-make-material-design-sliding-tabs.html By the way, what you need to is include in your project this code: https:\/\/developer.android.com\/samples\/SlidingTabsColors\/src\/com.example.android.common\/view\/SlidingTabLayout.html. So create a class in which you will paste the entire code. Then create your activity that extends ActionBarActivity like for example this one: public class MainActivity extends ActionBarActivity [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7979","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7979"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7979\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}