List of usage examples for android.support.v4.view GravityCompat START
int START
To view the source code for android.support.v4.view GravityCompat START.
Click Source Link
From source file:br.com.PartoHumanizado.viewholder.MenuDrawerViewHolder.java
private void onCreate() { menuDrawerFragment = (MenuDrawerFragment) activity.getSupportFragmentManager() .findFragmentById(R.id.navigation_drawer); mFragmentContainerView = activity.findViewById(R.id.navigation_drawer); mDrawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout); // 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 ActionBar actionBar = activity.getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) activity .findViewById(R.id.toolbar); mDrawerToggle = new ActionBarDrawerToggle(activity, mDrawerLayout, toolbar, R.string.open, R.string.close) // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. {// ww w. j a v a2 s . co m @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); } }; // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
From source file:com.example.android.support.design.widget.NavigationViewUsage.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.design_navigation); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mTextMessage = (TextView) findViewById(R.id.message); // Set the color of status bar TypedValue value = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimaryDark, value, true); mDrawerLayout.setStatusBarBackgroundColor(value.data); // Retrieve the Toolbar from our content view, and set it as the action bar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w .j ava 2s . com*/ // Toggle icon toolbar.setNavigationIcon(R.drawable.ic_action_navigation_menu); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mDrawerLayout.openDrawer(GravityCompat.START); } }); // Menu NavigationView navigation = (NavigationView) findViewById(R.id.navigation); navigation.setNavigationItemSelectedListener(mNavigationItemSelectedListener); navigation.inflateHeaderView(R.layout.design_navigation_header); }
From source file:com.arquitetaweb.ttinder.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle();/* w ww . j av a 2 s . c o m*/ mPlanetTitles = getResources().getStringArray(R.array.menu_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 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); } }
From source file:com.example.syb9111.myapplication.HomeActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: drawer.openDrawer(GravityCompat.START); return true; }/*from www. j ava2s . co m*/ return super.onOptionsItemSelected(item); }
From source file:com.github.blalasaadri.sprinttopics.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.drawer_activity); ButterKnife.bind(this); setSupportActionBar(toolbar);/*from w ww . java 2s . co m*/ mTitle = mDrawerTitle = getTitle(); // 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<>(this, R.layout.drawer_list_item, navigationListItems)); 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 */ 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.addDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
From source file:com.github.shareme.gwsmaterialdrawer.library.DrawerFrameLayout.java
@SuppressWarnings("deprecation") public DrawerFrameLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); inflate(context, R.layout.md_drawer_frame_layout, this); mDrawer = (DrawerView) findViewById(R.id.mdDrawer); setDrawerShadow(R.drawable.md_drawer_shadow, GravityCompat.START); TypedArray a = getContext().getTheme().obtainStyledAttributes(new int[] { R.attr.colorPrimaryDark }); int colorPrimaryDark = a.getColor(0, 0); if (colorPrimaryDark != 0) { setStatusBarBackgroundColor(colorPrimaryDark); } else {/*from w w w .j av a 2s . c o m*/ //TODO: getColor depreciated setStatusBarBackgroundColor(getResources().getColor(android.R.color.black)); } a = getContext().obtainStyledAttributes(attrs, new int[] { R.attr.drawerMaxWidth }); int drawerMaxWidth = a.getDimensionPixelSize(0, 0); if (drawerMaxWidth != 0) { setDrawerMaxWidth(drawerMaxWidth); } else { resetDrawerMaxWidth(); } a.recycle(); }
From source file:com.free.underground.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.i("mycode", "MainActivity onCreate"); //loadCategories(); mTitle = mDrawerTitle = getTitle();/* ww w . j a v a 2s. c om*/ mMenuTitles = getResources().getStringArray(R.array.menu_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mMenuTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); 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) { Log.i("mycode", "MainActivity selectItem"); selectItem(0); } DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int width = metrics.widthPixels; Log.i("mycode", "width " + width); }
From source file:circleplus.app.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle();/*from w w w. j a v a 2 s . c o m*/ mDrawerTitles = getResources().getStringArray(R.array.titles_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); // TODO: Make a custom ListView adapter, and add a HeaderView to the ListView // Set the drawer's list view with items and click listener mDrawerList .setAdapter(new ArrayAdapter<String>(MainActivity.this, R.layout.drawer_list_item, mDrawerTitles)); 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 proper interactions // between the sliding drawer and the ActionBar app icon mDrawerToggle = new ActionBarDrawerToggle(MainActivity.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 */ ) { /** Called when a drawer has settled in a completely closed state */ @Override public void onDrawerClosed(View view) { super.onDrawerClosed(view); getSupportActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } /** Called when a drawer has settled in a completely open state */ @Override public void onDrawerOpened(View view) { super.onDrawerOpened(view); getSupportActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
From source file:com.example.android.reward.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle();//from w w w.jav a 2 s.co m mPlanetTitles = getResources().getStringArray(R.array.planets_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); frameLayout = (FrameLayout) findViewById(R.id.content_frame); // 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 getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); getActionBar().hide(); // 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); } }
From source file:android.support.v7.app.DrawerLayoutActivity.java
@Override protected void onContentViewSet() { super.onContentViewSet(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawer = (ListView) findViewById(R.id.start_drawer); mContent = (TextView) findViewById(R.id.content_text); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // The drawer title must be set in order to announce state changes when // accessibility is turned on. This is typically a simple description, // e.g. "Navigation". mDrawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.drawer_title)); mDrawer.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Shakespeare.TITLES)); mDrawer.setOnItemClickListener(new DrawerItemClickListener()); // Find the toolbar in our layout and set it as the support action bar on the activity. // This is required to have the drawer slide "over" the toolbar. mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar.setTitle(R.string.drawer_title); setSupportActionBar(mToolbar);/*from w w w . j a va2 s .co m*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(false); // ActionBarDrawerToggle provides convenient helpers for tying together the // prescribed interactions between a top-level sliding drawer and the action bar. // Note that, as the Javadocs of ActionBarDrawerToggle constructors say, we are // *not* using a constructor that gets a Toolbar since we're setting our toolbar // dynamically at runtime. Furthermore, as the drawer is sliding over the toolbar, // we are suppressing the morphing animation from hamburger to back arrow by // calling super.onDrawerSlide with slideOffset=0.0f. In case your app only has // top-level pages and doesn't need back arrow visuals at all, you can set up // your activity theme to have attribute named "drawerArrowStyle" that points // to an extension of Widget.AppCompat.DrawerArrowToggle that has its "spinBars" // attribute set to false. mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); super.onDrawerSlide(drawerView, 0.0f); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, 0.0f); } }; mDrawerLayout.addDrawerListener(mDrawerToggle); // Configure the background color fill of the system status bar (on supported platform // versions) and the toolbar itself. We're using the same color, and android:statusBar // from the theme makes the status bar slightly darker. final int metalBlueColor = getResources().getColor(R.color.drawer_sample_metal_blue); mDrawerLayout.setStatusBarBackgroundColor(metalBlueColor); mToolbar.setBackgroundColor(metalBlueColor); // Register a pre-draw listener to get the initial width of the DrawerLayout so // that we can determine the width of the drawer based on the Material spec at // https://www.google.com/design/spec/patterns/navigation-drawer.html#navigation-drawer-specs mDrawerLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { // What is the width of the entire DrawerLayout? final int drawerLayoutWidth = mDrawerLayout.getWidth(); // What is the action bar size? final Resources.Theme theme = mDrawerLayout.getContext().getTheme(); final TypedArray a = theme .obtainStyledAttributes(new int[] { android.support.v7.appcompat.R.attr.actionBarSize }); final int actionBarSize = a.getDimensionPixelSize(0, 0); if (a != null) { a.recycle(); } // Compute the width of the drawer and set it on the layout params. final int idealDrawerWidth = 5 * actionBarSize; final int maxDrawerWidth = Math.max(0, drawerLayoutWidth - actionBarSize); final int drawerWidth = Math.min(idealDrawerWidth, maxDrawerWidth); final DrawerLayout.LayoutParams drawerLp = (DrawerLayout.LayoutParams) mDrawer.getLayoutParams(); drawerLp.width = drawerWidth; mDrawer.setLayoutParams(drawerLp); // Remove ourselves as the pre-draw listener since this is a one-time // configuration. mDrawerLayout.getViewTreeObserver().removeOnPreDrawListener(this); return true; } }); }