Java Code Examples for android.support.v4.widget.DrawerLayout#setDrawerShadow()
The following examples show how to use
android.support.v4.widget.DrawerLayout#setDrawerShadow() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoreMaterialActivity.java From MaterialDesignSupport with MIT License | 6 votes |
private void setupLeftNavigationMenu() { DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); LinearLayout drawer = (LinearLayout) findViewById(R.id.left_drawer); View drawerContent = LayoutInflater.from(this).inflate(R.layout.core_material_drawer, new RelativeLayout(CoreMaterialApplication.getContext()), false); drawer.addView(drawerContent); AnimatedExpandableListView drawerList = (AnimatedExpandableListView) findViewById(R.id.left_drawer_list); mDrawerAdapter = new DrawerListRowAdapter(drawerList, this); drawerList.setAdapter(mDrawerAdapter); setupDrawerListRows(true); }
Example 2
Source File: MainActivity.java From KA27 with Apache License 2.0 | 5 votes |
/** * Define all views */ private void setView() { mScrimInsetsFrameLayout = (ScrimInsetsFrameLayout) findViewById(R.id.scrimInsetsFrameLayout); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); if (mDrawerLayout != null) { mDrawerLayout.setStatusBarBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.statusbar_color)); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); } mDrawerList = (RecyclerView) findViewById(R.id.drawer_list); mSplashView = (SplashView) findViewById(R.id.splash_view); LinearLayoutManager mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); mLayoutManager.setSmoothScrollbarEnabled(true); mDrawerList.setLayoutManager(mLayoutManager); mDrawerList.setHasFixedSize(true); mDrawerList.setAdapter(new RecyclerView.Adapter() { @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return null; } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {} @Override public int getItemCount() { return 0; } }); }
Example 3
Source File: MainActivity.java From kernel_adiutor with Apache License 2.0 | 5 votes |
/** * Define all views */ private void setView() { mScrimInsetsFrameLayout = (ScrimInsetsFrameLayout) findViewById(R.id.scrimInsetsFrameLayout); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); if (mDrawerLayout != null) { mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.statusbar_color)); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); } mDrawerList = (RecyclerView) findViewById(R.id.drawer_list); mSplashView = (SplashView) findViewById(R.id.splash_view); LinearLayoutManager mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); mLayoutManager.setSmoothScrollbarEnabled(true); mDrawerList.setLayoutManager(mLayoutManager); mDrawerList.setHasFixedSize(true); mDrawerList.setAdapter(new RecyclerView.Adapter() { @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return null; } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { } @Override public int getItemCount() { return 0; } }); }
Example 4
Source File: HomeActivity.java From Dashboard with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setActionBarIcon(R.drawable.ic_ab_drawer); GridView gridView = (GridView) findViewById(R.id.gridView); gridView.setAdapter(new GridViewAdapter()); gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { String url = (String) view.getTag(); DetailActivity.launch(HomeActivity.this, view.findViewById(R.id.image), url); } }); drawer = (DrawerLayout) findViewById(R.id.drawer); drawer.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START); //TODO Customize Dialog if (prefs.getBoolean("firstrun", true)) { new MaterialDialog.Builder(this) .title("Loading") .content("It may take some time for the wallpapers to load. We're sorry for that but don't worry, this is just for the first start. After that the wallpapers are stored in the cache. Go and get some cookies :)") .positiveText("Okay.") .show(); prefs.edit().putBoolean("firstrun", false).apply(); } }
Example 5
Source File: MainActivity.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
private void initDrawer() { drawerLayout = (DrawerLayout) findViewById(R.id.drawer); if (drawerLayout == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) return; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { int drawerResId = ThemeUtils.getThemeResId(getTheme(), R.attr.iconDrawer); drawerToggle = new ActionBarDrawerToogleV4(this, drawerLayout, drawerResId, R.string.drawer_open, R.string.drawer_close) { @SuppressWarnings("deprecation") @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (tabsAdapter != null) tabsAdapter.setDraggingItem(-1); } @SuppressWarnings("deprecation") @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) CompatibilityImpl.showActionBar(MainActivity.this); } }; } else { drawerToggle = new ActionBarDrawerToogleV7(this, drawerLayout, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (tabsAdapter != null) tabsAdapter.setDraggingItem(-1); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) CompatibilityImpl.showActionBar(MainActivity.this); } }; } drawerLayout.setDrawerListener(drawerToggle); drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, DRAWER_GRAVITY); CompatibilityImpl.activeActionBar(this); }
Example 6
Source File: MainActivity.java From android-MaterialNavigationDrawer with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); RecyclerView drawerOptions = (RecyclerView) findViewById(R.id.drawer_options); setSupportActionBar(toolbar); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close); drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START); drawerLayout.setStatusBarBackground(R.color.primary_dark); drawerLayout.setDrawerListener(drawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); List<DrawerItem> drawerItems = Arrays.asList( new DrawerItem(DrawerItem.Type.HEADER), new DrawerMenu().setIconRes(R.drawable.ic_group).setText(getString(R.string.menu_template, 1)), new DrawerMenu().setIconRes(R.drawable.ic_map).setText(getString(R.string.menu_template, 2)), new DrawerItem(DrawerItem.Type.DIVIDER), new DrawerMenu().setIconRes(R.drawable.ic_person).setText(getString(R.string.menu_template, 3)), new DrawerMenu().setIconRes(R.drawable.ic_search).setText(getString(R.string.menu_template, 4)), new DrawerItem(DrawerItem.Type.DIVIDER), new DrawerMenu().setIconRes(R.drawable.ic_settings).setText(getString(R.string.menu_template, 5))); drawerOptions.setLayoutManager(new LinearLayoutManager(this)); DrawerItemAdapter adapter = new DrawerItemAdapter(drawerItems); adapter.setOnItemClickListener(new DrawerItemAdapter.OnItemClickListener() { @Override public void onClick(View view, int position) { onDrawerMenuSelected(position); } }); drawerOptions.setAdapter(adapter); drawerOptions.setHasFixedSize(true); if (savedInstanceState == null) setupFragment(new SimpleFramgment()); }
Example 7
Source File: MainDrawerMenu.java From 4pdaClient-plus with Apache License 2.0 | 5 votes |
public MainDrawerMenu(MainActivity activity, SelectItemListener listener) { prefs = App.getInstance().getPreferences(); DisplayMetrics displayMetrics = App.getInstance().getResources().getDisplayMetrics(); float dpWidth = displayMetrics.widthPixels; if (dpWidth > displayMetrics.density * 400) { dpWidth = displayMetrics.density * 400; } dpWidth -= 80 * displayMetrics.density; mActivity = activity; mSelectItemListener = listener; mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawer = (NavigationView) findViewById(R.id.left_drawer); mDrawer.setNavigationItemSelectedListener(this); DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) mDrawer.getLayoutParams(); params.width = (int) dpWidth; if ("right".equals(Preferences.System.getDrawerMenuPosition())) { params.gravity = Gravity.RIGHT; mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_end, GravityCompat.END); } else { mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_start, GravityCompat.START); } mDrawer.setLayoutParams(params); setNavigationItems(); mDrawerToggle = new ActionBarDrawerToggle(mActivity, mDrawerLayout, mActivity.toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); mActivity.hidePopupWindows(); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.syncState(); }
Example 8
Source File: MainActivity.java From OPFPush with Apache License 2.0 | 5 votes |
private void setupNavigationDrawer() { final Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupportActionBar(toolbar); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, 0, 0); drawerLayout.setDrawerListener(drawerToggle); }
Example 9
Source File: HomeActivity.java From Dashboard with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setActionBarIcon(R.drawable.ic_ab_drawer); GridView gridView = (GridView) findViewById(R.id.gridView); gridView.setAdapter(new GridViewAdapter()); gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { String url = (String) view.getTag(); DetailActivity.launch(HomeActivity.this, view.findViewById(R.id.image), url); } }); drawer = (DrawerLayout) findViewById(R.id.drawer); drawer.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START); //TODO Customize Dialog if (prefs.getBoolean("firstrun", true)) { new MaterialDialog.Builder(this) .title("Loading") .content("It may take some time for the wallpapers to load. We're sorry for that but don't worry, this is just for the first start. After that the wallpapers are stored in the cache. Go and get some cookies :)") .positiveText("Okay.") .show(); prefs.edit().putBoolean("firstrun", false).apply(); } }
Example 10
Source File: HomeACTIVITY.java From ALLGO with Apache License 2.0 | 5 votes |
/** * drawer 的初始化方法 */ private void creatdrawer() { // TODO 生成抽屉方法开始 mTitle = mDrawerTitle = getTitle(); mHomeTitles = getResources().getStringArray(R.array.home_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new ArrayAdapter<String>(this,R.layout.drawer_list_item,mHomeTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer mActionBar.setDisplayHomeAsUpEnabled(true); mActionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { mActionBar.setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() 此时关闭抽屉 } public void onDrawerOpened(View drawerView) { mActionBar.setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() 此时打开抽屉 View v=mDrawerList.getChildAt(position); v.setBackgroundColor(Color.GRAY); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); }
Example 11
Source File: NavigationDrawerActivity.java From android-NavigationDrawer with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_navigation_drawer); mTitle = mDrawerTitle = getTitle(); mPlanetTitles = getResources().getStringArray(R.array.planets_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (RecyclerView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // improve performance by indicating the list if fixed size. mDrawerList.setHasFixedSize(true); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new PlanetAdapter(mPlanetTitles, this)); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
Example 12
Source File: NavigationDrawerActivity.java From UltimateAndroid with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fading_actionbar_activity_navigation_drawer); mTitle = mDrawerTitle = getTitle(); mCityNames = getResources().getStringArray(R.array.drawer_items); TypedArray typedArray = getResources().obtainTypedArray(R.array.city_images); mCityImages = new int [typedArray.length()]; for (int i = 0; i < typedArray.length(); ++i) { mCityImages[i] = typedArray.getResourceId(i, 0); } typedArray.recycle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.fading_actionbar_drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.fading_actionbar_drawer_list_item, mCityNames)); mDrawerList.setOnItemClickListener(this); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.fading_actionbar_ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
Example 13
Source File: BaseDrawerFragment.java From android-atleap with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mFragmentContainerView = getActivity().findViewById(mDrawerConfig.fragmentContainerId); View view = getActivity().findViewById(mDrawerConfig.drawerLayoutViewId); if (view != null && view instanceof DrawerLayout) { mDrawerLayout = (DrawerLayout)view; } ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); if (mDrawerLayout != null) { // set a custom shadow that overlays the main content when the drawer opens if (mDrawerConfig.drawerShadowResourceId != 0) mDrawerLayout.setDrawerShadow(mDrawerConfig.drawerShadowResourceId, GravityCompat.START); createActionBarDrawerToggle(); // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); } initUpIcon(); }
Example 14
Source File: MainActivity.java From ui with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle(); mPlanetTitles = getResources().getStringArray(R.array.planets_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ // R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ //no in the v7 constructor, so commented out. R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getSupportActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
Example 15
Source File: FileChooserActivity.java From MFileChooser with MIT License | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int main = this.getResources().getIdentifier("main", "layout", this.getPackageName()); int internal = this.getResources().getIdentifier("internal", "string", this.getPackageName()); int drawer_layout = this.getResources().getIdentifier("drawer_layout", "id", this.getPackageName()); int left_drawer = this.getResources().getIdentifier("left_drawer", "id", this.getPackageName()); int drawer_shadow = this.getResources().getIdentifier("drawer_shadow", "drawable", this.getPackageName()); int ic_navigation_drawer = this.getResources().getIdentifier("ic_navigation_drawer", "drawable", this.getPackageName()); int drawer_open = this.getResources().getIdentifier("drawer_open", "string", this.getPackageName()); int drawer_close = this.getResources().getIdentifier("drawer_close", "string", this.getPackageName()); setContentView(main); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); _context = this; Bundle extras = getIntent().getExtras(); if (extras != null) { if (extras .getStringArrayList(Constants.KEY_FILTER_FILES_EXTENSIONS) != null) { extensions = extras .getStringArrayList(Constants.KEY_FILTER_FILES_EXTENSIONS); fileFilter = new FileFilter() { @Override public boolean accept(File pathname) { return ((pathname.isDirectory()) || (pathname.getName() .contains(".") ? extensions.contains(pathname .getName().substring( pathname.getName().lastIndexOf(".")).toLowerCase()) : false)); } }; } } currentFolder = new File(Environment.getExternalStorageDirectory() .getAbsolutePath()); currentCategory = new Category(); currentCategory.title = getString(internal); currentCategory.path = currentFolder.getAbsolutePath(); mDrawerLayout = (DrawerLayout) findViewById(drawer_layout); mDrawerLayout.setDrawerShadow(drawer_shadow,GravityCompat.START); mDrawerList = (ListView) findViewById(left_drawer); mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ ic_navigation_drawer, /* nav drawer image to replace 'Up' caret */ drawer_open, /* "open drawer" description for accessibility */ drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { // getSupportActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to // onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { // getSupportActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to // onPrepareOptionsMenu() } }; mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); // ActionBar. //getSupportActionBar().set fill(currentFolder); }
Example 16
Source File: NavActivity.java From blog-nested-fragments-backstack with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_nav); mTitle = mDrawerTitle = getTitle(); mTitles = getResources().getStringArray(R.array.titles); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
Example 17
Source File: NavigationDrawerActivity.java From FadingActionBar with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_navigation_drawer); mTitle = mDrawerTitle = getTitle(); mCityNames = getResources().getStringArray(R.array.drawer_items); TypedArray typedArray = getResources().obtainTypedArray(R.array.city_images); mCityImages = new int [typedArray.length()]; for (int i = 0; i < typedArray.length(); ++i) { mCityImages[i] = typedArray.getResourceId(i, 0); } typedArray.recycle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mCityNames)); mDrawerList.setOnItemClickListener(this); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
Example 18
Source File: SilentActivity.java From KUAS-AP-Material with MIT License | 4 votes |
public void setUpMenuDrawer(int selectItem) { drawer = (DrawerLayout) findViewById(R.id.drawer_layout); navigationView = (NavigationView) findViewById(R.id.nav_view); headerView = navigationView.getHeaderView(0); if (headerView.findViewById(R.id.layout_user) != null) { final boolean isLogin = Memory.getBoolean(this, Constant.PREF_IS_LOGIN, false); headerView.findViewById(R.id.layout_user) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { drawer.closeDrawers(); if (mLayoutID == R.layout.activity_messages || mLayoutID == R.layout.activity_about) { if (isLogin) { showUserInfo(); } else { startActivity( new Intent(SilentActivity.this, LoginActivity.class)); } } else if (mLayoutID == R.layout.activity_login) { Toast.makeText(SilentActivity.this, R.string.login_first, Toast.LENGTH_SHORT).show(); } else { showUserInfo(); } } }); } drawer.setDrawerShadow(R.drawable.shadow_right, GravityCompat.START); drawer.setStatusBarBackgroundColor(ContextCompat.getColor(this, R.color.main_theme_dark)); mDrawerToggle = new AnimationActionBarDrawerToggle(this, drawer, R.string.open_drawer, R.string.close_drawer) { @Override public void onDrawerSlide(View drawerView, float slideOffset) { if (drawerView == navigationView) { super.onDrawerSlide(drawerView, slideOffset); InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(drawerView.getWindowToken(), 0); } } /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View drawerView) { if (drawerView == navigationView) { super.onDrawerClosed(drawerView); InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(drawerView.getWindowToken(), 0); } } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { if (drawerView == navigationView) { super.onDrawerOpened(drawerView); InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(drawerView.getWindowToken(), 0); } } }; // Set the drawer toggle as the DrawerListener drawer.setDrawerListener(mDrawerToggle); navigationView.setNavigationItemSelectedListener(this); mSelectedItem = -1; if (-1 < selectItem && selectItem < navigationView.getMenu().size()) { selectedMenuItem = navigationView.getMenu().getItem(selectItem); selectedMenuItem.setChecked(true); mSelectedItem = selectItem; } }
Example 19
Source File: MainActivity.java From EventApp with Apache License 2.0 | 4 votes |
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** * Called when a drawer has settled in a completely closed * state. */ public void onDrawerClosed(View view) { setTitle(mTitle); } /** * Called when a drawer has settled in a completely open * state. */ public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle( getResources().getString(R.string.drawer_name)); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mRooms = getResources().getStringArray(R.array.rooms_array); mDrawerList = (ListView) findViewById(R.id.left_drawer); // Set the adapter for the list view mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mRooms)); // Set the list's click listener mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); }
Example 20
Source File: BarometerNetworkActivity.java From PressureNet with GNU General Public License v3.0 | 2 votes |
private void addDrawerLayout() { drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerList = (ListView) findViewById(R.id.left_drawer); drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // Set the adapter for the list view drawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, drawerListContents)); // Set the list's click listener drawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { hideKeyboard(); super.onDrawerClosed(view); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { hideKeyboard(); super.onDrawerOpened(drawerView); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; drawerToggle.setDrawerIndicatorEnabled(true); // Set the drawer toggle as the DrawerListener drawerLayout.setDrawerListener(drawerToggle); }