当前位置: 首页>>代码示例>>Java>>正文


Java ActionBar.setHomeAsUpIndicator方法代码示例

本文整理汇总了Java中android.support.v7.app.ActionBar.setHomeAsUpIndicator方法的典型用法代码示例。如果您正苦于以下问题:Java ActionBar.setHomeAsUpIndicator方法的具体用法?Java ActionBar.setHomeAsUpIndicator怎么用?Java ActionBar.setHomeAsUpIndicator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.app.ActionBar的用法示例。


在下文中一共展示了ActionBar.setHomeAsUpIndicator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setTitleBar

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
private void setTitleBar() {
        setSupportActionBar(binding.titleToolBar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            //去除默认Title显示
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(R.drawable.icon_back);
//            actionBar.setTitle(subjectsBean.getTitle());
//            actionBar.setSubtitle("主演:" + StringFormatUtil.formatName(subjectsBean.getCasts()));
        }

        // title
        binding.tvTitle.setText(subjectsBean.getTitle());
        // 副标题
        binding.tvSubtitle.setText("主演:" + StringFormatUtil.formatName(subjectsBean.getCasts()));

        binding.titleToolBar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
 
开发者ID:joelan,项目名称:ClouldReader,代码行数:25,代码来源:SlideScrollViewActivity.java

示例2: onCreate

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_request_edit);

    ButterKnife.bind(this);

    setSupportActionBar(toolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
        actionBar.setTitle(R.string.title_edit_request);
    }
}
 
开发者ID:jboss-outreach,项目名称:rest-android,代码行数:17,代码来源:EditRequestActivity.java

示例3: onCreate

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_postulaciones_activas);
    // Setting ViewPager for each Tabs
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager_pa);
    setupViewPager(viewPager);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerpa);
    // Adding menu icon to Toolbar
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        VectorDrawableCompat indicator
                = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu, getTheme());
        indicator.setTint(ResourcesCompat.getColor(getResources(),R.color.white,getTheme()));
        supportActionBar.setHomeAsUpIndicator(indicator);
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }

}
 
开发者ID:sloiza,项目名称:changApp,代码行数:20,代码来源:PostulacionesActivasActivity.java

示例4: initNavigation

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
private void initNavigation() {
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navView = (NavigationView) findViewById(R.id.nav_view);
      ActionBar actionBar = getSupportActionBar();
      if (actionBar != null) {
          actionBar.setDisplayHomeAsUpEnabled(true);
          actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);
      }
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(MenuItem item) {
              switch (item.getItemId()) {
                  case R.id.nav_devices:
                      break;
                  case R.id.nav_lab:
                      break;
                  case R.id.nav_information:
                      break;
                  case R.id.nav_settings:
                      break;
                  case R.id.nav_about:
                      break;
              }
              mDrawerLayout.closeDrawers();
              return true;
          }
      });

      mSwipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh);
      mSwipeRefresh.setColorSchemeResources(R.color.colorPrimary);
      mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
              if (mMeshSvc != null && !mMeshSvc.isOnline()) {
                  refreshDeviceNode();
              }
          }
      });
  }
 
开发者ID:blxble,项目名称:mesh-core-on-android,代码行数:42,代码来源:MainActivity.java

示例5: onCreate

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        dbManager = DBManager.getInstance(HomeActivity.this);
        toolbar = (Toolbar)findViewById(R.id.home_activity_toolbar);
        setSupportActionBar(toolbar);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        navView = (NavigationView) findViewById(R.id.nav_view);
        View headerView = navView.getHeaderView(0);
        navHeadIv = (ImageView)headerView.findViewById(R.id.nav_head_bg_iv);
        loadBingPic();
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(R.drawable.drawer_menu);
        }
        refreshNightModeTitle();
        navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem item) {
                mDrawerLayout.closeDrawers();
                switch (item.getItemId()){
                    case R.id.nav_theme:
                        isStartTheme = true;
                        Intent intentTheme = new Intent(HomeActivity.this,ThemeActivity.class);
                        startActivity(intentTheme);
                        break;
                    case R.id.nav_night_mode:
                        int preTheme = 0;
                        if(MyMusicUtil.getNightMode(HomeActivity.this)){
                            //当前为夜间模式,则恢复之前的主题
                            MyMusicUtil.setNightMode(HomeActivity.this,false);
                            preTheme = MyMusicUtil.getPreTheme(HomeActivity.this);
                            MyMusicUtil.setTheme(HomeActivity.this,preTheme);
                        }else {
                            //当前为白天模式,则切换到夜间模式
                            MyMusicUtil.setNightMode(HomeActivity.this,true);
                            MyMusicUtil.setTheme(HomeActivity.this,ThemeActivity.THEME_SIZE-1);
                        }
//                        Intent intentNight = new Intent(HomeActivity.this,HomeActivity.class);
//                        startActivity(intentNight);
                        recreate();
                        refreshNightModeTitle();
//                        overridePendingTransition(R.anim.start_anim,R.anim.out_anim);
                        break;
                    case R.id.nav_about_me:
                        Intent aboutTheme = new Intent(HomeActivity.this,AboutActivity.class);
                        startActivity(aboutTheme);
                        break;
                    case R.id.nav_logout:
                        finish();
                        Intent intentBroadcast = new Intent(MusicPlayerService.PLAYER_MANAGER_ACTION);
                        intentBroadcast.putExtra(Constant.COMMAND, Constant.COMMAND_RELEASE);
                        sendBroadcast(intentBroadcast);
                        Intent stopIntent = new Intent(HomeActivity.this,MusicPlayerService.class);
                        stopService(stopIntent);
                        break;
                }
                return true;
            }
        });
        init();

        Intent startIntent = new Intent(HomeActivity.this,MusicPlayerService.class);
        startService(startIntent);

    }
 
开发者ID:lijunyandev,项目名称:MeetMusic,代码行数:69,代码来源:HomeActivity.java

示例6: initTitle

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
private void initTitle() {
    //设置状态栏颜色
    StatusBarUtil.setColor(this, CommonUtils.getColor(R.color.colorTheme), 0);
    //初始化相关控件
    mProgressBar = (ProgressBar) findViewById(R.id.pb_progress);
    webView = (WebView) findViewById(R.id.webview_detail);
    videoFullView = (FrameLayout) findViewById(R.id.video_fullView);
    mTitleToolBar = (Toolbar) findViewById(R.id.title_tool_bar);

    setSupportActionBar(mTitleToolBar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        //去除默认Title显示
        actionBar.setDisplayShowTitleEnabled(false);
        //显示默认back键
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.icon_back);
    }
    setTitle(mTitle);

    //给默认back键设置点击事件
    mTitleToolBar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
}
 
开发者ID:jutao,项目名称:GankReader,代码行数:29,代码来源:WebViewActivity.java

示例7: initMainToolbar

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
public void initMainToolbar() {
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final ActionBar actionBar = getSupportActionBar();

    if (actionBar != null) {
        actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}
 
开发者ID:hernandazevedo,项目名称:starwarsshop,代码行数:11,代码来源:BaseActivity.java

示例8: onCreate

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(this.getIntent() != null) {
        this._SourceUrl = this.getIntent().getStringExtra(EXTRA_IMAGE_SOURCE);
        if(this._SourceUrl != null) {
            ImageView _ImageView = new TouchImageView(this);
            _ImageView.setBackgroundColor(Color.WHITE);
            _ImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            _ImageView.setAdjustViewBounds(true);
            try {
                Customerly.get()._RemoteImageHandler.request(new IU_RemoteImageHandler.Request()
                        .fitCenter()
                        .load(this._SourceUrl)
                        .into(this, _ImageView)
                        .placeholder(R.drawable.io_customerly__pic_placeholder_fullscreen));
                super.setContentView(_ImageView);

                final ActionBar actionBar = this.getSupportActionBar();
                if (actionBar != null) {
                    String title;
                    if(Customerly.get().__PING__LAST_widget_color != 0) {
                        actionBar.setBackgroundDrawable(new ColorDrawable(Customerly.get().__PING__LAST_widget_color));
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            this.getWindow().setStatusBarColor(IU_Utils.alterColor(Customerly.get().__PING__LAST_widget_color, 0.8f));
                        }

                        if (IU_Utils.getContrastColor(Customerly.get().__PING__LAST_widget_color) == Color.BLACK) {
                            actionBar.setHomeAsUpIndicator(R.drawable.io_customerly__ic_arrow_back_black_24dp);
                            title = String.format("<font color='#000000'>%1$s</font>", actionBar.getTitle());

                        } else {
                            actionBar.setHomeAsUpIndicator(R.drawable.io_customerly__ic_arrow_back_white_24dp);
                            title = String.format("<font color='#ffffff'>%1$s</font>", actionBar.getTitle());
                        }
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                            actionBar.setTitle(Html.fromHtml(title, 0));
                        } else {
                            //noinspection deprecation
                            actionBar.setTitle(Html.fromHtml(title));
                        }
                    }
                    actionBar.setDisplayHomeAsUpEnabled(true);
                }
                return;
            } catch (Exception glideException) {
                IEr_CustomerlyErrorHandler.sendError(IEr_CustomerlyErrorHandler.ERROR_CODE__GLIDE_ERROR, "Error during Glide loading in FullScreenImage_Activity", glideException);
            }
        }
    }
    this.finish();
}
 
开发者ID:customerly,项目名称:Customerly-Android-SDK,代码行数:53,代码来源:IAct_FullScreenImage.java

示例9: setTitleBar

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
/**
 * toolbar设置
 */
private void setTitleBar() {
    setSupportActionBar(binding.titleToolBar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        //去除默认Title显示
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.icon_back);
    }
    // 手动设置才有效果
    binding.titleToolBar.setTitleTextAppearance(this, R.style.ToolBar_Title);
    binding.titleToolBar.setSubtitleTextAppearance(this, R.style.Toolbar_SubTitle);

    binding.titleToolBar.setTitle(subjectsBean.getTitle());
    binding.titleToolBar.setSubtitle(String.format("主演:%s", StringFormatUtil.formatName(subjectsBean.getCasts())));

    binding.titleToolBar.inflateMenu(R.menu.movie_detail);
    binding.titleToolBar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.actionbar_more));
    binding.titleToolBar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    binding.titleToolBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.actionbar_more:// 更多信息
                    WebViewActivity.loadUrl(MovieDetailActivity.this,mMoreUrl,mMovieName);
                    break;
            }
            return false;
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:41,代码来源:MovieDetailActivity.java

示例10: configureSupportActionBar

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
@Override
public void configureSupportActionBar(Toolbar toolbar, Drawable icon) {
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(icon);
    }
    mDialogOpen = true;
}
 
开发者ID:mvescovo,项目名称:item-reaper,代码行数:12,代码来源:ItemsActivity.java

示例11: setHomeAsUpIndicator

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
/** 设置ActionBar左上角图标 */
protected void setHomeAsUpIndicator(@DrawableRes int resId) {
	ActionBar actionBar = getSupportActionBar();
	if (actionBar != null) {
		actionBar.setHomeAsUpIndicator(resId);
	}
}
 
开发者ID:PlutoArchitecture,项目名称:Pluto-Android,代码行数:8,代码来源:PlutoActivity.java

示例12: onCreate

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_motive);
    Toolbar toolbar = (Toolbar) findViewById(R.id.theme_toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar!=null){
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.title_back);
    }

    initView();
}
 
开发者ID:wendyltan,项目名称:EasyTodo,代码行数:15,代码来源:MotiveActivity.java

示例13: onCreate

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent Startservice=new Intent(this, SearchService.class);
    startService(Startservice);


    SharedPreferences prefs=getSharedPreferences("user", Context.MODE_PRIVATE);
    editor=prefs.edit();
    boolean isGuideLoaded=prefs.getBoolean("denglu",false);
    username=prefs.getString("username",null);

    if (!isGuideLoaded){

        Intent intent=new Intent(MainActivity.this,LoginActivity.class);
        startActivity(intent);
        MainActivity.this.finish();
    }

    navView= (NavigationView)findViewById(R.id.nav_view);
     toolbar= (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar=getSupportActionBar();

    if (actionBar!=null){
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.mipmap.gengduo);
        actionBar.setTitle(" ");
    }

    replaceFragment(new ViewPagerFragmwnt());
    List<String> permissionList = new ArrayList<>();
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION);
    }
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        permissionList.add(Manifest.permission.READ_PHONE_STATE);
    }
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
        permissionList.add(Manifest.permission.CAMERA);
    }
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED){
        permissionList.add(Manifest.permission.READ_CONTACTS);

    }
    if (!permissionList.isEmpty()) {
        String [] permissions = permissionList.toArray(new String[permissionList.size()]);
        ActivityCompat.requestPermissions(MainActivity.this, permissions, 1);
    } else {
        init();
    }


}
 
开发者ID:Shmilyz,项目名称:Swap,代码行数:60,代码来源:MainActivity.java

示例14: onCreate

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    try {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings_dots_style);

        //Show back button
        ActionBar ab = getSupportActionBar();
        if (ab != null) {
            ab.setDisplayHomeAsUpEnabled(true);
            ab.setHomeAsUpIndicator(R.mipmap.ic_arrow_back_white_24dp);
        }

        //Speak the title of the activity
        Common.defaultTextSpeech.speechText(getString(R.string.dot_style));

        //Buttons declaration
        dotFillColor = (Button) findViewById(R.id.dotFillColor);
        previousDotFillColor = Common.dotFillColor;
        dotFillColor.setBackgroundColor(previousDotFillColor);
        dotStrokeColor = (Button) findViewById(R.id.dotStrokeColor);
        previousDotStrokeColor = Common.dotStrokeColor;
        dotStrokeColor.setBackgroundColor(previousDotStrokeColor);
        resetSettingsBtn = (Button) findViewById(R.id.resetSettingsBtn);

        //Spinner declaration
        dotRadiusPortraitSpinner = (Spinner) findViewById(R.id.dotRadiusPortraitSpinner);
        dotRadiusLandscapeSpinner = (Spinner) findViewById(R.id.dotRadiusLandscapeSpinner);

        //Portrait dots radius array list
        int thePortraitDefaultDotRadius = Common.getDefaultDotRadius(0);
        ArrayList<String> portraitDotRadiusList = new ArrayList<>();
        for (int x = Common.MIN_DOT_RADIUS; x <= (thePortraitDefaultDotRadius + 20); x++) {
            portraitDotRadiusList.add(String.format(Locale.getDefault(), "%d", x));
        }

        //Portrait dots radius adapter
        portraitDotRadiusAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, portraitDotRadiusList);
        portraitDotRadiusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        dotRadiusPortraitSpinner.setAdapter(portraitDotRadiusAdapter);
        dotRadiusPortraitSpinner.setSelection(portraitDotRadiusAdapter.getPosition(String.format(Locale.getDefault(), "%d", Common.getSettingInt("dotRadius", thePortraitDefaultDotRadius))), true);

        //Landscape dots radius array list
        int theLandscapeDefaultDotRadius = Common.getDefaultDotRadius(1);
        ArrayList<String> landscapeDotRadiusList = new ArrayList<>();
        for (int x = Common.MIN_DOT_RADIUS; x <= (theLandscapeDefaultDotRadius + 20); x++) {
            landscapeDotRadiusList.add(String.format(Locale.getDefault(), "%d", x));
        }

        //Landscape dots radius adapter
        landscapeDotRadiusAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, landscapeDotRadiusList);
        landscapeDotRadiusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        dotRadiusLandscapeSpinner.setAdapter(landscapeDotRadiusAdapter);
        dotRadiusLandscapeSpinner.setSelection(landscapeDotRadiusAdapter.getPosition(String.format(Locale.getDefault(), "%d", Common.getSettingInt("dotLandscapeRadius", theLandscapeDefaultDotRadius))), true);

        //Switches declaration
        fillDotOnTouch = (CheckBox) findViewById(R.id.fillDotOnTouch);
        fillDotOnTouch.setChecked(Common.fillDotOnTouch);
        fillDotOnTouch.setOnCheckedChangeListener(this);
        viewBrailleDotNumber = (CheckBox) findViewById(R.id.viewBrailleDotNumber);
        viewBrailleDotNumber.setChecked(Common.viewBrailleDotNumber);

        //Add listeners to spinners
        initListeners(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:MohammadAlBanna,项目名称:Swift-Braille-Soft-keyboard,代码行数:69,代码来源:DotsStyleActivity.java

示例15: onCreate

import android.support.v7.app.ActionBar; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_view);

    mToolbar = (Toolbar) findViewById(R.id.id_toolbar);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.activity_navigation);
    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    //<activity android:name=".NavigationActivity" android:theme="@style/AppThemeNoActionBar"></activity>  
    //<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">  
    //初始化toolbar,这里得使用NoActionBar的主题,使用ToolBar替换系统自带的ActionBar达到自己的需求  
    setSupportActionBar(mToolbar);
    ActionBar actionBar = getSupportActionBar();
    //关联图标和侧滑栏  
    actionBar.setHomeAsUpIndicator(R.drawable.menu);
    //设置actionBar和侧滑栏关联  
    actionBar.setDisplayHomeAsUpEnabled(true);
    //初始化drawerlayout和navigationview  
    if (mNavigationView != null) {
        //设置监听回调  
        mNavigationView.setNavigationItemSelectedListener(new NavigationView
                .OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                //根据选中不同的选项来进行不同的操作  
                switch (item.getItemId()) {
                    case R.id.nav_home:
                        getSupportFragmentManager().beginTransaction().replace(R.id.content,
                                ItemFragement.newInstance("主页")).commit();
                        mToolbar.setTitle("主页");
                        break;
                    case R.id.nav_friends:
                        getSupportFragmentManager().beginTransaction().replace(R.id.content,
                                ItemFragement.newInstance("我的好友")).commit();
                        mToolbar.setTitle("我的好友");
                        break;
                    case R.id.nav_discussion:
                        getSupportFragmentManager().beginTransaction().replace(R.id.content, 
                                ItemFragement.newInstance("热文论坛")).commit();
                        mToolbar.setTitle("热文论坛");
                        break;
                    case R.id.nav_messages:
                        getSupportFragmentManager().beginTransaction().replace(R.id.content,
                                ItemFragement.newInstance("我的消息")).commit();
                        mToolbar.setTitle("我的消息");
                        break;
                    case R.id.sub1:
                        getSupportFragmentManager().beginTransaction().replace(R.id.content,
                                ItemFragement.newInstance("子项1")).commit();
                        mToolbar.setTitle("子项1");
                        break;
                    case R.id.sub2:
                        getSupportFragmentManager().beginTransaction().replace(R.id.content,
                                ItemFragement.newInstance("子项2")).commit();
                        mToolbar.setTitle("子项2");
                        break;
                }
                //设置选项选中效果  
                item.setChecked(true);
                //选了侧边栏选项之后,关闭侧边栏  
                mDrawerLayout.closeDrawers();
                //这里返回true有选中的效果,源码中有解释  
                return true;
            }
        });
    }

}
 
开发者ID:zuoni1018,项目名称:CoordinatorLayoutExample-master,代码行数:69,代码来源:DrawLayoutSample.java


注:本文中的android.support.v7.app.ActionBar.setHomeAsUpIndicator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。