當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。