Hide Toolbar when scrolling content up.

This commit is contained in:
Alex Ning 2019-04-23 08:03:29 +08:00
parent d8ddad9522
commit 6bd4b41f8c
7 changed files with 97 additions and 110 deletions

View File

@ -20,7 +20,6 @@ import androidx.lifecycle.ViewModelProviders;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.chip.Chip; import com.google.android.material.chip.Chip;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -93,10 +92,6 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
String title = "r/" + subredditName; String title = "r/" + subredditName;
subredditNameTextView.setText(title); subredditNameTextView.setText(title);
CollapsingToolbarLayout collapsingToolbarLayout = findViewById(R.id.collapsing_toolbar_layout_view_subreddit_detail_activity);
collapsingToolbarLayout.setTitleEnabled(false);
Toolbar toolbar = findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(title); toolbar.setTitle(title);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);

View File

@ -19,7 +19,6 @@ import androidx.lifecycle.ViewModelProviders;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.chip.Chip; import com.google.android.material.chip.Chip;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -90,9 +89,6 @@ public class ViewUserDetailActivity extends AppCompatActivity {
String title = "u/" + userName; String title = "u/" + userName;
userNameTextView.setText(title); userNameTextView.setText(title);
CollapsingToolbarLayout collapsingToolbarLayout = findViewById(R.id.collapsing_toolbar_layout_view_user_detail_activity);
collapsingToolbarLayout.setTitleEnabled(false);
Toolbar toolbar = findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(title); toolbar.setTitle(title);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -37,39 +36,39 @@
android:id="@+id/profile_linear_layout_main_activity" android:id="@+id/profile_linear_layout_main_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="16dp" android:background="?attr/selectableItemBackground"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:background="?attr/selectableItemBackground"> android:padding="16dp">
<ImageView <ImageView
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginEnd="32dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:src="@drawable/ic_outline_account_circle_24px"/> android:layout_marginEnd="32dp"
android:src="@drawable/ic_outline_account_circle_24px" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/profile" android:text="@string/profile"
android:textColor="@android:color/black" android:textColor="@android:color/black" />
android:layout_gravity="center_vertical"/>
</LinearLayout> </LinearLayout>
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:background="#E0E0E0"/> android:background="#E0E0E0" />
<TextView <TextView
android:id="@+id/following_label_main_activity" android:id="@+id/following_label_main_activity"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/following"
android:layout_margin="16dp" android:layout_margin="16dp"
android:visibility="gone"/> android:text="@string/following"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/subscribed_user_recycler_view_main_activity" android:id="@+id/subscribed_user_recycler_view_main_activity"
@ -80,9 +79,9 @@
android:id="@+id/subscriptions_label_main_activity" android:id="@+id/subscriptions_label_main_activity"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/subscriptions"
android:layout_margin="16dp" android:layout_margin="16dp"
android:visibility="gone"/> android:text="@string/subscriptions"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/subscribed_subreddit_recycler_view_main_activity" android:id="@+id/subscribed_subreddit_recycler_view_main_activity"

View File

@ -8,15 +8,14 @@
tools:context=".ViewSubredditDetailActivity"> tools:context=".ViewSubredditDetailActivity">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout_view_subreddit_detail_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"> android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout <com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout_view_subreddit_detail_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:titleEnabled="false"
app:contentScrim="?attr/colorPrimary" app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
app:toolbarId="@+id/toolbar"> app:toolbarId="@+id/toolbar">

View File

@ -8,15 +8,14 @@
tools:context=".ViewUserDetailActivity"> tools:context=".ViewUserDetailActivity">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout_view_user_detail_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"> android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout <com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout_view_user_detail_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:titleEnabled="false"
app:contentScrim="?attr/colorPrimary" app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
app:toolbarId="@+id/toolbar"> app:toolbarId="@+id/toolbar">

View File

@ -11,6 +11,13 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"> android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:titleEnabled="false"
app:layout_scrollFlags="scroll|enterAlways"
app:toolbarId="@+id/toolbar">
<FrameLayout <FrameLayout
android:id="@+id/toolbar_frame_layout_main_activity" android:id="@+id/toolbar_frame_layout_main_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -19,9 +26,7 @@
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"/>
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<com.ferfalk.simplesearchview.SimpleSearchView <com.ferfalk.simplesearchview.SimpleSearchView
android:id="@+id/search_view_main_activity" android:id="@+id/search_view_main_activity"
@ -39,6 +44,8 @@
</FrameLayout> </FrameLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<View <View

View File

@ -43,12 +43,4 @@
</LinearLayout> </LinearLayout>
<!--<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_post_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@drawable/baseline_add_white_24" />-->
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>