zoukankan      html  css  js  c++  java
  • Activity返回按钮

    如图:

     1 package com.maomao.beautymovie;
     2 
     3 import android.app.ActionBar;
     4 import android.app.Activity;
     5 import android.os.Bundle;
     6 import android.support.v4.app.FragmentActivity;
     7 import android.view.KeyEvent;
     8 import android.view.MenuItem;
     9 
    10 
    11 /**
    12  * 
    13  * @author NINGXUEFENG
    14  *
    15  */
    16 public class BaseActivity extends Activity {
    17 
    18     protected ActionBar mActionBar;
    19 
    20     protected void onCreate(Bundle savedInstanceState) {
    21         super.onCreate(savedInstanceState);
    22         initActionBar();
    23     }
    24 
    25     private void initActionBar() {
    26         mActionBar = getActionBar();
    27         mActionBar.setDisplayHomeAsUpEnabled(true);             // 给左上角图标的左边加上一个返回的图标"《" 。对应ActionBar.DISPLAY_HOME_AS_UP
    28         mActionBar.setDisplayShowHomeEnabled(true);             //使左上角图标可点击,对应id为android.R.id.home,对应ActionBar.DISPLAY_SHOW_HOME false 则图标无法点击
    29         mActionBar.setHomeButtonEnabled(true);                  // false 就无法点击
    30     }
    31 
    32     public void setTitle(int resId) {
    33         mActionBar.setTitle(resId);
    34     }
    35 
    36     public void setTitle(CharSequence text) {
    37         mActionBar.setTitle(text);
    38     }
    39 
    40     @Override
    41     public boolean onOptionsItemSelected(MenuItem item) {
    42         switch (item.getItemId()) {
    43               case android.R.id.home:
    44                   onBackPressed();
    45                   return true;
    46             default:
    47                 return super.onOptionsItemSelected(item);
    48         }
    49     }
    50 
    51 
    52 }
  • 相关阅读:
    团队项目01应用场景
    团队项目冲刺第一阶段03
    团队冲刺第一阶段02
    团队冲刺第一阶段01
    基于 Scrapy-redis 的分布式爬虫详细设计
    创建CrawlSpider爬虫简要步骤
    如何将redis中的数据导入到本地MongoDB和MySQL数据库
    远程访问ubuntu下mysql的问题
    vi命令汇总
    Chrome/FireFox处理JSON的插件
  • 原文地址:https://www.cnblogs.com/ning1121/p/4378068.html
Copyright © 2011-2022 走看看