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