1a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov/* 2a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * Copyright (C) 2016 The Android Open Source Project 3a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * 4a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * Licensed under the Apache License, Version 2.0 (the "License"); 5a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * you may not use this file except in compliance with the License. 6a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * You may obtain a copy of the License at 7a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * 8a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * http://www.apache.org/licenses/LICENSE-2.0 9a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * 10a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * Unless required by applicable law or agreed to in writing, software 11a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * distributed under the License is distributed on an "AS IS" BASIS, 12a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * See the License for the specific language governing permissions and 14a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * limitations under the License. 15a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov */ 16a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov 17a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikovpackage com.example.android.support.design.widget; 18a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov 19a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikovimport android.os.Bundle; 20a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikovimport android.support.design.widget.TabLayout; 21a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikovimport android.support.v7.app.AppCompatActivity; 22a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikovimport android.support.v7.widget.Toolbar; 23a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikovimport com.example.android.support.design.R; 24a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov 25a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov/** 26a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov * This demonstrates usage of TabLayout with custom items 27a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov */ 28a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikovpublic class TabLayoutCustomItemsUsage extends AppCompatActivity { 29a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov 30a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov @Override 31a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov protected void onCreate(Bundle savedInstanceState) { 32a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov super.onCreate(savedInstanceState); 33a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov setContentView(R.layout.design_tabs_custom); 34a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov 35a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov // Retrieve the Toolbar from our content view, and set it as the action bar 36a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 37a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov setSupportActionBar(toolbar); 38a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov getSupportActionBar().setDisplayHomeAsUpEnabled(true); 39a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov 40a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov // Create three tabs with custom views 41a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); 42a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov for (int i = 0; i < 3; i++) { 43a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov TabLayout.Tab tab = tabLayout.newTab(); 44a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov 45a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov tabLayout.addTab(tab); 46a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov tab.setCustomView(R.layout.design_tab_custom); 47a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov } 48a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov } 49a7b32567b7cae0d71c71b7260e038fa59568434bKirill Grouchnikov} 50