Commit 88ca7a04872445351c0a0025d41997fe9aaf7018
1 parent
9983a422
- add expand toolbar code
Showing
2 changed files
with
17 additions
and
1 deletions
app/src/main/java/net/devfac/userstory/MainActivity.java
... | ... | @@ -2,6 +2,8 @@ package net.devfac.userstory; |
2 | 2 | |
3 | 3 | import android.content.Intent; |
4 | 4 | import android.os.Bundle; |
5 | +import android.support.design.widget.AppBarLayout; | |
6 | +import android.support.design.widget.CoordinatorLayout; | |
5 | 7 | import android.support.design.widget.FloatingActionButton; |
6 | 8 | import android.support.design.widget.Snackbar; |
7 | 9 | import android.support.design.widget.TabLayout; |
... | ... | @@ -39,6 +41,8 @@ public class MainActivity extends AppCompatActivity |
39 | 41 | private ViewPager mViewPagerMain; |
40 | 42 | private ViewPagerAdapter mViewPagerAdapter; |
41 | 43 | private TabLayout mTabLayoutMain; |
44 | + private AppBarLayout mAppBarMain; | |
45 | + private CoordinatorLayout mCoordinateMain; | |
42 | 46 | |
43 | 47 | FloatingActionButton mFab; |
44 | 48 | |
... | ... | @@ -87,6 +91,14 @@ public class MainActivity extends AppCompatActivity |
87 | 91 | @Override |
88 | 92 | public void onPageSelected(int position) { |
89 | 93 | if (mViewPagerAdapter.getPosition(Constants.FRAGMENT_TITLE_BOOK_SHELF) == position) { |
94 | + } else if (mViewPagerAdapter.getPosition(Constants.FRAGMENT_TITLE_ADD_BOOK) == position) { | |
95 | + //Expand toolbar | |
96 | + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarMain.getLayoutParams(); | |
97 | + AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior(); | |
98 | + if (behavior != null) { | |
99 | + behavior.setTopAndBottomOffset(0); | |
100 | + behavior.onNestedPreScroll(mCoordinateMain, mAppBarMain, null, 0, 1, new int[2]); | |
101 | + } | |
90 | 102 | } |
91 | 103 | } |
92 | 104 | |
... | ... | @@ -99,6 +111,9 @@ public class MainActivity extends AppCompatActivity |
99 | 111 | mTabLayoutMain = (TabLayout)findViewById(R.id.tablayout_main); |
100 | 112 | mTabLayoutMain.setupWithViewPager(mViewPagerMain); |
101 | 113 | |
114 | + mAppBarMain = (AppBarLayout)findViewById(R.id.appBarLayoutMain); | |
115 | + mCoordinateMain = (CoordinatorLayout)findViewById(R.id.coordinator_main); | |
116 | + | |
102 | 117 | mFab = (FloatingActionButton) findViewById(R.id.fab); |
103 | 118 | mFab.setOnClickListener(new View.OnClickListener() { |
104 | 119 | @Override | ... | ... |
app/src/main/res/layout/app_bar_main.xml
... | ... | @@ -3,12 +3,13 @@ |
3 | 3 | xmlns:android="http://schemas.android.com/apk/res/android" |
4 | 4 | xmlns:app="http://schemas.android.com/apk/res-auto" |
5 | 5 | xmlns:tools="http://schemas.android.com/tools" |
6 | + android:id="@+id/coordinator_main" | |
6 | 7 | android:layout_width="match_parent" |
7 | 8 | android:layout_height="match_parent" |
8 | 9 | tools:context=".MainActivity"> |
9 | 10 | |
10 | 11 | <android.support.design.widget.AppBarLayout android:layout_height="wrap_content" |
11 | - android:id="@+id/appBarLayout" | |
12 | + android:id="@+id/appBarLayoutMain" android:animateLayoutChanges="true" | |
12 | 13 | android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> |
13 | 14 | |
14 | 15 | <android.support.v7.widget.Toolbar android:id="@+id/toolbar_main" | ... | ... |