README.md
1Android HorizontalPaging Sample
2===================================
3
4This sample shows how to implement tabs, using Fragments and a ViewPager.
5
6Introduction
7------------
8
9This sample implements tabs using the deprecated [ActionBar.TabListener][1]. It uses [ViewPager][2] and
10[FragmentPagerAdapter][3] to handle swiping between tabs and displaying the selected tab content.
11
12
131. Create an Activity that extends [FragmentActivity][4], with a [ViewPager][2] for its layout.
142. Implement [ActionBar.TabListener][1] interface.
153. Create a class that extends [FragmentPagerAdapter][3] and override its `getItem(int position)`,
16`getCount()` and `getPageTitle(int position)` methods.
174. In the `onCreate(Bundle savedInstanceState)` method of your activity, set navigation mode to tabs for the
18ActionBar using `setNavigationMode(ActionBar.NAVIGATION_MODE_TABS)`. Note: This is DEPRECATED as of Android
19Lollipop.
205. Set your custom [FragmentPagerAdapter][3] on your [ViewPager][2].
216. Implement `setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener())` on your [ViewPager][2] to
22know the selected tab, so you can update your ActionBar with `setSelectedNavigationItem(position)`.
23
24[1]: http://developer.android.com/reference/android/support/v7/app/ActionBar.TabListener.html
25[2]: http://developer.android.com/reference/android/support/v4/view/ViewPager.html
26[3]: http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html
27[4]: http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html
28
29Pre-requisites
30--------------
31
32- Android SDK v21
33- Android Build Tools v21.1.1
34- Android Support Repository
35
36Screenshots
37-------------
38
39<img src="screenshots/1-tab1.png" height="400" alt="Screenshot"/> <img src="screenshots/2-tab2.png" height="400" alt="Screenshot"/>
40
41Getting Started
42---------------
43
44This sample uses the Gradle build system. To build this project, use the
45"gradlew build" command or use "Import Project" in Android Studio.
46
47Support
48-------
49
50- Google+ Community: https://plus.google.com/communities/105153134372062985968
51- Stack Overflow: http://stackoverflow.com/questions/tagged/android
52
53If you've found an error in this sample, please file an issue:
54https://github.com/googlesamples/android-HorizontalPaging
55
56Patches are encouraged, and may be submitted by forking this project and
57submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
58
59License
60-------
61
62Copyright 2014 The Android Open Source Project, Inc.
63
64Licensed to the Apache Software Foundation (ASF) under one or more contributor
65license agreements. See the NOTICE file distributed with this work for
66additional information regarding copyright ownership. The ASF licenses this
67file to you under the Apache License, Version 2.0 (the "License"); you may not
68use this file except in compliance with the License. You may obtain a copy of
69the License at
70
71http://www.apache.org/licenses/LICENSE-2.0
72
73Unless required by applicable law or agreed to in writing, software
74distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
75WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
76License for the specific language governing permissions and limitations under
77the License.
78