Home | History | Annotate | Download | only in styled
      1 /*
      2  * Copyright (C) 2013 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.actionbarcompat.styled;
     18 
     19 import android.os.Bundle;
     20 import android.support.v4.app.FragmentTransaction;
     21 import android.support.v7.app.ActionBar;
     22 import android.support.v7.app.ActionBarActivity;
     23 import android.view.Menu;
     24 
     25 /**
     26  * This sample shows you how to use ActionBarCompat with a customized theme. It utilizes a split
     27  * action bar when running on a device with a narrow display, and show three tabs.
     28  *
     29  * This Activity extends from {@link ActionBarActivity}, which provides all of the function
     30  * necessary to display a compatible Action Bar on devices running Android v2.1+.
     31  *
     32  * The interesting bits of this sample start in the theme files
     33  * ('res/values/styles.xml' and 'res/values-v14</styles.xml').
     34  *
     35  * Many of the drawables used in this sample were generated with the
     36  * 'Android Action Bar Style Generator': http://jgilfelt.github.io/android-actionbarstylegenerator
     37  */
     38 public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {
     39 
     40     @Override
     41     protected void onCreate(Bundle savedInstanceState) {
     42         super.onCreate(savedInstanceState);
     43         setContentView(R.layout.sample_main);
     44 
     45         // Set the Action Bar to use tabs for navigation
     46         ActionBar ab = getSupportActionBar();
     47         ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
     48 
     49         // Add three tabs to the Action Bar for display
     50         ab.addTab(ab.newTab().setText("Tab 1").setTabListener(this));
     51         ab.addTab(ab.newTab().setText("Tab 2").setTabListener(this));
     52         ab.addTab(ab.newTab().setText("Tab 3").setTabListener(this));
     53     }
     54 
     55     @Override
     56     public boolean onCreateOptionsMenu(Menu menu) {
     57         // Inflate menu from menu resource (res/menu/main)
     58         getMenuInflater().inflate(R.menu.main, menu);
     59 
     60         return super.onCreateOptionsMenu(menu);
     61     }
     62 
     63     // Implemented from ActionBar.TabListener
     64     @Override
     65     public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
     66         // This is called when a tab is selected.
     67     }
     68 
     69     // Implemented from ActionBar.TabListener
     70     @Override
     71     public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
     72         // This is called when a previously selected tab is unselected.
     73     }
     74 
     75     // Implemented from ActionBar.TabListener
     76     @Override
     77     public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
     78         // This is called when a previously selected tab is selected again.
     79     }
     80 }
     81