Change NavigationView items when user is logged

I thing the best approach to this is to include all your items in the menu and the change their visibility. <item android:id=”@+id/login” android:icon=”@drawable/ic_action_person” android:title=”@string/login” android:visible=”true” /> <item android:id=”@+id/logout” android:icon=”@drawable/ic_action_person” android:title=”@string/logout” android:visible=”false” /> then navigationView.getMenu().findItem(R.id.login).setVisible(false); navigationView.getMenu().findItem(R.id.logout).setVisible(true); You can also do this with whole groups of items <group android:id=”@+id/group_1″ android:checkableBehavior=”single” android:visible=”false”> … </group> and navigationView.getMenu().setGroupVisible(R.id.group_1, true)

How can I add a custom item to a NavigationView with a menu layout?

The actionLayout attribute is now supported in Android Support Library 23.1: NavigationView provides a convenient way to build a navigation drawer, including the ability to creating menu items using a menu XML file. We’ve expanded the functionality possible with the ability to set custom views for items via app:actionLayout or using MenuItemCompat.setActionView(). So the code … Read more

Android 5.0 material design style navigation drawer for KitKat

You need to use the new Toolbar in the appcompat v21 and the new ActionBarDrawerToggle that is in this library as well. Add the gradle dependency to your gradle file: compile ‘com.android.support:appcompat-v7:21.0.0’ Your activity_main.xml layout would look something like that: <!–I use android:fitsSystemWindows because I am changing the color of the statusbar as well–> <LinearLayout … Read more

Manage toolbar’s navigation and back button from fragment in android

Add a toolbar to your xml <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:background=”?attr/colorPrimary” android:theme=”@style/ThemeOverlay.AppCompat.ActionBar” app:popupTheme=”@style/ThemeOverlay.AppCompat.Light”> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Fragment title”/> </android.support.v7.widget.Toolbar> Then inside your onCreateView method in the Fragment: Toolbar toolbar = view.findViewById(R.id.toolbar); toolbar.setNavigationIcon(R.drawable.ic_back_button); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getActivity().onBackPressed(); } });

Android – Switch ActionBar Back Button to Navigation Button

If I assume you’re using android.support.v4.widget.DrawerLayout in your layout, then this approach may work for you; I’ve only tested on API 21 but given it’s mostly using the support libraries, it should work (famous last words) on lower or higher targets. import android.support.v7.app.ActionBarDrawerToggle import android.support.v4.widget.DrawerLayout ActionBarDrawerToggle mDrawerToggle; DrawerLayout drawerLayout; private boolean mToolBarNavigationListenerIsRegistered = false; @Override … Read more

How to detect that the DrawerLayout started opening?

DEPRECATED: See other answers for a more suitable solution There are 2 possible ways to do that: Use onDrawerSlide(View drawerView, float slideOffset) callback slideOffset changes from 0 to 1. 1 means it is completely open, 0 – closed. Once offset changes from 0 to !0 – it means it started opening process. Something like: mDrawerToggle … Read more

DrawerLayout Double Drawer (Left and Right Drawers simultaneously)

Here is the code for a Double Drawer Activity than can be extended by other activities to implement the double drawer, assuming they have a layout like the one propposed by OP. public class DoubleDrawerActivity extends ActionBarActivity { private DrawerLayout mDrawerLayout; private ActionBarDrawerToggle mDrawerToggle; private View mLeftDrawerView; private View mRightDrawerView; @Override protected void onCreate(Bundle savedInstanceState) … Read more

NavigationView menu items with counter on the right

Starting from version 23 of appcompat-v7 NavigationView supports action views, so it is quite easy to implement counter yourself. Create counter layout, i.e. menu_counter.xml: <?xml version=”1.0″ encoding=”utf-8″?> <TextView xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”match_parent” android:gravity=”center_vertical” android:textAppearance=”@style/TextAppearance.AppCompat.Body2″ /> Reference it in your drawer menu xml, i.e. menu/drawer.xml: <item … app:actionLayout=”@layout/menu_counter” /> Note that you should use app namespace, don’t … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)