@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); ActionBar mActionBar = getSupportActionBar(); int color = getResources().getColor(R.color.toolbar_green); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Overview color MainActivity.this.setTaskDescription( new ActivityManager.TaskDescription( "Linode", AndroidHelper.drawableToBitmap(getResources().getDrawable(R.mipmap.ic_launcher)), color)); } if (mActionBar != null) { toolbar.setBackgroundColor(color); drawer .getDrawerLayout() .setStatusBarBackgroundColor( AndroidHelper.darkenColor(getResources().getColor(R.color.toolbar_green), 0.8f)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { toolbar.setElevation(8); } } }
public Drawer getMaterialDrawer() { AccountHeader headerResult = new AccountHeaderBuilder() .withActivity(activity) .withHeaderBackground(R.drawable.header_tourism) .withTranslucentStatusBar(false) .build(); Drawer result = new DrawerBuilder() .withActivity(activity) .withToolbar(toolbar) .withTranslucentStatusBar(true) .withAccountHeader(headerResult) .addDrawerItems( new PrimaryDrawerItem() .withName(R.string.navigation_item_map_name) .withIcon(R.drawable.ic_map) .withIdentifier(ITEM_MAP), new PrimaryDrawerItem() .withName(R.string.navigation_item_search_name) .withIcon(R.drawable.ic_magnify) .withIdentifier(ITEM_SEARCH), new PrimaryDrawerItem() .withName(R.string.navigation_item_marks_name) .withIcon(R.drawable.ic_bookmark) .withIdentifier(ITEM_MARKS), new DividerDrawerItem(), new PrimaryDrawerItem() .withName(R.string.navigation_item_settings_name) .withIcon(R.drawable.ic_settings) .withIdentifier(ITEM_SETTINGS), new PrimaryDrawerItem() .withName(R.string.navigation_item_help_name) .withIcon(R.drawable.ic_help) .withIdentifier(ITEM_HELP)) .withOnDrawerItemClickListener( new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { switch (drawerItem.getIdentifier()) { case ITEM_SEARCH: // Поиск. Intent search = new Intent(activity, SearchActivity.class); search.putExtra(Constants.USER_ID, Constants.DEFAULT_USER_ID_VALUE); activity.startActivityForResult(search, Constants.SHOW_SEARCH_ACTIVITY); break; case ITEM_MARKS: // Метки. Intent marks = new Intent(activity, MarksActivity.class); marks.putExtra(Constants.USER_ID, Constants.DEFAULT_USER_ID_VALUE); marks.putExtra(MarksActivity.CALL_FILTER_OR_ADD_MARKS, false); activity.startActivityForResult(marks, Constants.SHOW_MARKS_ACTIVITY); break; case ITEM_SETTINGS: // Настройки. Intent settings = new Intent(activity, SettingsActivity.class); activity.startActivityForResult(settings, Constants.SHOW_SETTINGS_ACTIVITY); break; case ITEM_HELP: // Помощь. Intent help = new Intent(activity, HelpActivity.class); activity.startActivityForResult(help, Constants.SHOW_HELP_ACTIVITY); break; } return false; } }) .withSelectedItem(1) .build(); // Анимация проворота иконки при клике на нее для вызова drawer-а. ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( activity, result.getDrawerLayout(), toolbar, R.string.navigation_view_open, R.string.navigation_view_close); result.getDrawerLayout().setDrawerListener(toggle); toggle.syncState(); return result; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fabric.with(this, new Crashlytics()); setContentView(R.layout.activity_main); // Find the toolbar in XML toolbar = (Toolbar) findViewById(R.id.toolbar); // Set it's title text color to white toolbar.setTitleTextColor(Color.parseColor("#FFFFFF")); // Change activity's action bar to toolbar setSupportActionBar(toolbar); LinodeApi.init(getBaseContext(), this); initImageLoader(); accountHeader = buildHeader(); // Set up a new drawer builder drawer = new DrawerBuilder() .withActivity(this) // Bind it to this activity .withToolbar(toolbar) // Bind it to the toolbar attached to this activity .withAccountHeader(accountHeader) .withTranslucentNavigationBar(true) // Disable translucent navigation menu/bar .addDrawerItems( // Add our drawer items // Regular drawer items new PrimaryDrawerItem() .withIcon(R.drawable.server) // Icon .withSelectedIcon(R.drawable.server_tinted) // Tinted icon .withName(getResources().getString(R.string.item1)) // Title .withIdentifier(1) // ID = 1 .withTextColor(Color.parseColor("#444444")) // Text color .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)), new PrimaryDrawerItem() .withIcon(R.drawable.sitemap) .withSelectedIcon(R.drawable.sitemap_tinted) // Tinted icon .withName(getResources().getString(R.string.item2)) .withIdentifier(2) // ID = 2 .withTextColor(Color.parseColor("#444444")) .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)), new PrimaryDrawerItem() .withIcon(R.drawable.dns) .withSelectedIcon(R.drawable.dns_tinted) // Tinted icon .withName(getResources().getString(R.string.item3)) .withIdentifier(3) // ID = 3 .withTextColor(Color.parseColor("#444444")) .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)), new PrimaryDrawerItem() .withIcon(R.drawable.library) .withSelectedIcon(R.drawable.library_tinted) // Tinted icon .withName(getResources().getString(R.string.item4)) .withIdentifier(4) // ID = 4 .withTextColor(Color.parseColor("#444444")) .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)), // Divider new DividerDrawerItem(), // Small/secondary drawer items new SecondaryDrawerItem() .withIcon(R.drawable.account) .withSelectedIcon( R.drawable .account_tinted) // Tinted icon; not mandatory since this won't be // highlighted .withName(getResources().getString(R.string.item5)) .withIdentifier(5) // ID = 5 .withTextColor(Color.parseColor("#444444")) .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)) .withSelectable(false), // Not a fragment; don't highlight new SecondaryDrawerItem() .withIcon(R.drawable.information) .withSelectedIcon(R.drawable.information_tinted) .withName(getResources().getString(R.string.item6)) .withIdentifier(6) // ID = 6 .withTextColor(Color.parseColor("#444444")) .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)) .withSelectable(false), // Not a fragment; don't highlight new SecondaryDrawerItem() .withIcon(R.drawable.logout) .withSelectedIcon(R.drawable.logout_tinted) .withName(getResources().getString(R.string.item7)) .withIdentifier(7) // ID = 7 .withTextColor(Color.parseColor("#444444")) .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)) .withSelectable(false) // Not a fragment; don't highlight ) // Attach onClickListeners for each drawer item (not dividers!) .withOnDrawerItemClickListener( new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { if (drawerItem != null) { // update the main content by replacing fragments Fragment fragment = new LinodesFragment(); FragmentManager fragmentManager = getFragmentManager(); switch ((int) drawerItem.getIdentifier()) { case 1: fragment = new LinodesFragment(); break; case 2: fragment = new NodesFragment(); break; case 3: fragment = new DNSFragment(); break; case 4: fragment = new LibraryFragment(); break; case 5: // Account Toast.makeText(getBaseContext(), "Demo Only", Toast.LENGTH_SHORT).show(); break; case 6: // About Intent about = new Intent(MainActivity.this, AboutActivity.class); startActivity(about); break; case 7: // Log out Toast.makeText(getBaseContext(), "Demo Only", Toast.LENGTH_SHORT).show(); break; } fragmentManager .beginTransaction() .replace(R.id.content_frame, fragment) .commit(); if (drawerItem instanceof Nameable) { setTitle( ((Nameable) drawerItem).getName().getText(getApplicationContext())); } } return false; } }) .withFireOnInitialOnClick(true) .withSavedInstance(savedInstanceState) .build(); // Set a custom shadow that overlays the main content when the drawer opens drawer.getDrawerLayout().setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); ActionBar mActionBar = getSupportActionBar(); int color = getResources().getColor(R.color.toolbar_green); if (mActionBar != null) { toolbar.setBackgroundColor(color); drawer .getDrawerLayout() .setStatusBarBackgroundColor( AndroidHelper.darkenColor(getResources().getColor(R.color.toolbar_green), 0.8f)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { toolbar.setElevation(8); getWindow() .setNavigationBarColor( AndroidHelper.darkenColor(getResources().getColor(R.color.toolbar_green), 0.8f)); } } }