Last active
April 19, 2018 09:11
-
-
Save piyush-malaviya/4b3a9d3c1ac81b1982af4eba58b855c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.support.v4.view.GravityCompat; | |
import android.support.v4.widget.DrawerLayout; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.Toolbar; | |
import android.view.View; | |
import android.widget.TextView; | |
public class ToolbarUtils { | |
public static void setToolbar(AppCompatActivity activity, Toolbar toolbar, String title) { | |
if (activity.getSupportActionBar() == null) { | |
return; | |
} | |
TextView tvTitle = (TextView) toolbar.findViewById(R.id.tvTitle); | |
tvTitle.setText(title); | |
} | |
public static void setToolbar(AppCompatActivity activity, Toolbar toolbar, DrawerLayout drawer, String title) { | |
if (activity.getSupportActionBar() == null) { | |
return; | |
} | |
toolbar.setNavigationIcon(R.drawable.ic_menu_white); | |
toolbar.setTag("Outer"); | |
TextView tvTitle = (TextView) toolbar.findViewById(R.id.tvTitle); | |
tvTitle.setText(title); | |
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED); | |
} | |
public static void setInnerToolbar(final AppCompatActivity activity, final Toolbar toolbar, final DrawerLayout drawer, String title) { | |
if (activity.getSupportActionBar() == null) { | |
return; | |
} | |
toolbar.setNavigationIcon(R.drawable.ic_back_white); | |
toolbar.setTag("Inner"); | |
TextView tvTitle = (TextView) toolbar.findViewById(R.id.tvTitle); | |
tvTitle.setText(title); | |
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); | |
toolbar.setNavigationOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
if (toolbar.getTag().equals("Inner")) { | |
activity.onBackPressed(); | |
} else { | |
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED); | |
drawer.openDrawer(GravityCompat.START); | |
toolbar.setNavigationIcon(R.drawable.ic_menu_white); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment