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