1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.support.design.widget; 18 19import android.content.Context; 20import android.graphics.drawable.Drawable; 21import android.support.design.R; 22import android.support.v7.widget.TintTypedArray; 23import android.util.AttributeSet; 24import android.view.View; 25 26/** 27 * TabItem is a special 'view' which allows you to declare tab items for a {@link TabLayout} 28 * within a layout. This view is not actually added to TabLayout, it is just a dummy which allows 29 * setting of a tab items's text, icon and custom layout. See TabLayout for more information on how 30 * to use it. 31 * 32 * @attr ref android.support.design.R.styleable#TabItem_android_icon 33 * @attr ref android.support.design.R.styleable#TabItem_android_text 34 * @attr ref android.support.design.R.styleable#TabItem_android_layout 35 * 36 * @see TabLayout 37 */ 38public final class TabItem extends View { 39 final CharSequence mText; 40 final Drawable mIcon; 41 final int mCustomLayout; 42 43 public TabItem(Context context) { 44 this(context, null); 45 } 46 47 public TabItem(Context context, AttributeSet attrs) { 48 super(context, attrs); 49 50 final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, 51 R.styleable.TabItem); 52 mText = a.getText(R.styleable.TabItem_android_text); 53 mIcon = a.getDrawable(R.styleable.TabItem_android_icon); 54 mCustomLayout = a.getResourceId(R.styleable.TabItem_android_layout, 0); 55 a.recycle(); 56 } 57}