zoukankan      html  css  js  c++  java
  • ActionBar窗口应用

      1 package com.example.day11_actionbardemo;
      2 
      3 import android.os.Bundle;
      4 import android.app.ActionBar;
      5 import android.app.ActionBar.OnNavigationListener;
      6 import android.app.FragmentTransaction;
      7 import android.app.ActionBar.Tab;
      8 import android.app.ActionBar.TabListener;
      9 import android.app.Activity;
     10 import android.view.Menu;
     11 import android.view.MenuItem;
     12 import android.widget.ArrayAdapter;
     13 import android.widget.Toast;
     14 
     15 public class MainActivity extends Activity {
     16     ActionBar bar;
     17     
     18     String[] phone = {"未接电话","已接电话","已拨电话"};
     19     @Override
     20     protected void onCreate(Bundle savedInstanceState) {
     21         super.onCreate(savedInstanceState);
     22         setContentView(R.layout.activity_main);
     23         
     24         init();
     25     }
     26     //11111111111111111111111111111111111
     27     @Override
     28     public boolean onMenuItemSelected(int featureId, MenuItem item) {
     29         // TODO Auto-generated method stub
     30         int id = item.getItemId();
     31         if(id == android.R.id.home){
     32             this.finish();
     33         }
     34         
     35         return super.onMenuItemSelected(featureId, item);
     36     }
     37     
     38     public void init(){
     39         bar = getActionBar();//获得actionbar
     40 //        bar.setDisplayShowHomeEnabled(false);
     41 //        bar.setDisplayShowTitleEnabled(false);
     42         bar.setDisplayHomeAsUpEnabled(true);//激活图标的功能
     43         
     44         //设置actionbar的样式,,,tab样式
     45 //        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);//设置为tab页的样式
     46 //        bar.setTitle("选项卡");
     47 //        //添加选项卡(功能项)
     48 //        bar.addTab(bar.newTab().setText("未接电话").setIcon(R.drawable.ic_launcher).setTabListener(l));
     49 //        bar.addTab(bar.newTab().setText("已接电话").setIcon(R.drawable.ic_launcher).setTabListener(l));
     50 //        bar.addTab(bar.newTab().setText("已拨电话").setIcon(R.drawable.ic_launcher).setTabListener(l));
     51         
     52         bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);//设置为list列表样式
     53         //创建适配器,配置导航项
     54         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, phone);
     55         //配置数据,并添加监听
     56         bar.setListNavigationCallbacks(adapter, new OnNavigationListener() {
     57             
     58             @Override
     59             public boolean onNavigationItemSelected(int itemPosition, long itemId) {
     60                 // TODO Auto-generated method stub
     61                 Toast.makeText(MainActivity.this, "您当前选中的是:"+phone[itemPosition], 0).show();
     62                 if(phone[itemPosition].equals("未接电话")){
     63                     
     64                 }else if(phone[itemPosition].equals("已接电话")){
     65                     
     66                 }
     67                 return false;
     68             }
     69         });
     70         
     71     }
     72     
     73     TabListener l = new TabListener() {
     74         
     75         @Override
     76         public void onTabUnselected(Tab tab, FragmentTransaction ft) {
     77             // TODO Auto-generated method stub
     78             
     79         }
     80         
     81         @Override
     82         public void onTabSelected(Tab tab, FragmentTransaction ft) {
     83             // TODO Auto-generated method stub
     84             Toast.makeText(MainActivity.this, tab.getText(), 0).show();
     85             if(tab.getText().equals("未接电话")){
     86                 
     87             }else if(tab.getText().equals("已接电话")){
     88                 
     89             }
     90             
     91         }
     92         @Override
     93         public void onTabReselected(Tab tab, FragmentTransaction ft) {
     94             // TODO Auto-generated method stub
     95             
     96         }
     97     };
     98 
     99     @Override
    100     public boolean onCreateOptionsMenu(Menu menu) {
    101         // Inflate the menu; this adds items to the action bar if it is present.
    102         getMenuInflater().inflate(R.menu.activity_main, menu);
    103         return true;
    104     }
    105 
    106 }
  • 相关阅读:
    Heterogeneity Wins
    Android使用ImageView显示网络图片
    Android OOM的解决方式
    洛谷P3390 【模板】矩阵快速幂
    CF732D. Exams[二分答案 贪心]
    洛谷P3388 【模板】割点
    POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]
    NOI2001|POJ1182食物链[种类并查集 向量]
    HDU3038 How Many Answers Are Wrong[带权并查集]
    NOIP2010关押罪犯[并查集|二分答案+二分图染色 | 种类并查集]
  • 原文地址:https://www.cnblogs.com/1426837364qqcom/p/5156942.html
Copyright © 2011-2022 走看看