Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright (C) 2008 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 
     17 package com.example.android.apis.view;
     18 
     19 import com.example.android.apis.R;
     20 
     21 import android.app.TabActivity;
     22 import android.os.Bundle;
     23 import android.view.View;
     24 import android.widget.TabHost;
     25 import android.widget.TextView;
     26 
     27 /**
     28  * Example of using a tab content factory for the content via {@link TabHost.TabSpec#setContent(android.widget.TabHost.TabContentFactory)}
     29  *
     30  * It also demonstrates using an icon on one of the tabs via {@link TabHost.TabSpec#setIndicator(CharSequence, android.graphics.drawable.Drawable)}
     31  *
     32  */
     33 public class Tabs2 extends TabActivity implements TabHost.TabContentFactory {
     34 
     35     @Override
     36     protected void onCreate(Bundle savedInstanceState) {
     37         super.onCreate(savedInstanceState);
     38 
     39         final TabHost tabHost = getTabHost();
     40         tabHost.addTab(tabHost.newTabSpec("tab1")
     41                 .setIndicator("tab1", getResources().getDrawable(R.drawable.star_big_on))
     42                 .setContent(this));
     43         tabHost.addTab(tabHost.newTabSpec("tab2")
     44                 .setIndicator("tab2")
     45                 .setContent(this));
     46         tabHost.addTab(tabHost.newTabSpec("tab3")
     47                 .setIndicator("tab3")
     48                 .setContent(this));
     49     }
     50 
     51     /** {@inheritDoc} */
     52     public View createTabContent(String tag) {
     53         final TextView tv = new TextView(this);
     54         tv.setText("Content for tab with tag " + tag);
     55         return tv;
     56     }
     57 }
     58