Adds RecyclerView in a CoordinatorLayout w/ a collapsing app bar.
Bug: 330062053
Test: No tests, just sample
Change-Id: If659f93e8c2fcde9e50c47500a8d84e5e23fef16
diff --git a/samples/Support4Demos/src/main/AndroidManifest.xml b/samples/Support4Demos/src/main/AndroidManifest.xml
index 59c0a48..c3cfdba 100644
--- a/samples/Support4Demos/src/main/AndroidManifest.xml
+++ b/samples/Support4Demos/src/main/AndroidManifest.xml
@@ -449,6 +449,17 @@
+ android:name=".widget.RecyclerViewWithCollapsingToolbarActivity"
+ android:exported="true"
+ android:theme="@style/Theme.AppCompat.Light"
+ android:label="@string/recycler_view_with_collapsing_toolbar">
+
+
+
+
+
+
+
android:name=".graphics.RoundedBitmapDrawableActivity"
android:exported="true"
android:label="Graphics/RoundedBitmapDrawable">
diff --git a/samples/Support4Demos/src/main/java/com/example/android/supportv4/widget/RecyclerViewWithCollapsingToolbarActivity.java b/samples/Support4Demos/src/main/java/com/example/android/supportv4/widget/RecyclerViewWithCollapsingToolbarActivity.java
new file mode 100644
index 0000000..dbcd566
--- /dev/null
+++ b/samples/Support4Demos/src/main/java/com/example/android/supportv4/widget/RecyclerViewWithCollapsingToolbarActivity.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.android.supportv4.widget;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.example.android.supportv4.R;
+import com.google.android.material.appbar.CollapsingToolbarLayout;
+
+import org.jspecify.annotations.NonNull;
+import org.jspecify.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Demonstrates the use of recycler view in nested scrolling (testing scrolling with a keyboard).
+ * See the associated layout file for details.
+ */
+public class RecyclerViewWithCollapsingToolbarActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_recycler_view_with_collapsing_toolbar);
+
+ CollapsingToolbarLayout collapsingToolbar = findViewById(R.id.collapsing_toolbar_layout);
+ collapsingToolbar.setTitle(
+ getResources().getString(R.string.preference_screen_collapsing_appbar_title)
+ );
+ collapsingToolbar.setContentScrimColor(getResources().getColor(R.color.color1));
+
+ RecyclerView recyclerView = findViewById(R.id.recycler_view);
+ recyclerView.setLayoutManager(new LinearLayoutManager(this));
+
+ List data = new ArrayList();
+ for (int index = 0; index < 14; index++) {
+ data.add(String.valueOf(index));
+ }
+
+ MyAdapter adapter = new MyAdapter(data);
+ recyclerView.setAdapter(adapter);
+ }
+
+ public static class MyAdapter extends RecyclerView.Adapter {
+ private final List mDataForItems;
+
+ public MyAdapter(@NonNull List items) {
+ this.mDataForItems = items;
+ }
+
+ public static class ViewHolder extends RecyclerView.ViewHolder {
+ @NonNull public TextView textViewHeader;
+ @NonNull public TextView textViewSubHeader;
+
+ public ViewHolder(@NonNull View itemView) {
+ super(itemView);
+ textViewHeader = itemView.findViewById(R.id.textViewHeader);
+ textViewSubHeader = itemView.findViewById(R.id.textViewSubHeader);
+ }
+ }
+
+ @Override
+ public MyAdapter.@NonNull ViewHolder onCreateViewHolder(
+ @NonNull ViewGroup parent,
+ int viewType
+ ) {
+ View itemView = LayoutInflater.from(parent.getContext()).inflate(
+ R.layout.recycler_view_with_collapsing_toolbar_list_item,
+ parent,
+ false
+ );
+ return new ViewHolder(itemView);
+ }
+
+ @Override
+ public void onBindViewHolder(
+ MyAdapter.@NonNull ViewHolder holder,
+ int position
+ ) {
+ String number = mDataForItems.get(position);
+
+ holder.textViewHeader.setText(number);
+ holder.textViewSubHeader.setText("Sub Header for " + number);
+ }
+
+ @Override
+ public int getItemCount() {
+ return mDataForItems.size();
+ }
+ }
+}
diff --git a/samples/Support4Demos/src/main/res/layout/activity_recycler_view_with_collapsing_toolbar.xml b/samples/Support4Demos/src/main/res/layout/activity_recycler_view_with_collapsing_toolbar.xml
new file mode 100644
index 0000000..7078a3d
--- /dev/null
+++ b/samples/Support4Demos/src/main/res/layout/activity_recycler_view_with_collapsing_toolbar.xml
@@ -0,0 +1,64 @@
+
+
+
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:fitsSystemWindows="true"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".widget.RecyclerViewWithCollapsingToolbarActivity">
+
+
+
+ android:layout_width="match_parent"
+ android:layout_height="200dp">
+
+
+ android:id="@+id/collapsing_toolbar_layout"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:expandedTitleMarginStart="48dp"
+ app:expandedTitleMarginEnd="64dp"
+ app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
+
+
+ android:layout_height="200dp"
+ android:background="@color/color2"/>
+
+
+ android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ app:layout_collapseMode="pin" />
+
+
+
+
+
+ android:layout_height="match_parent"
+ android:layout_width="match_parent"
+ android:orientation="vertical"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior">
+
+
+ android:id="@+id/recycler_view"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+
+
diff --git a/samples/Support4Demos/src/main/res/layout/recycler_view_with_collapsing_toolbar_list_item.xml b/samples/Support4Demos/src/main/res/layout/recycler_view_with_collapsing_toolbar_list_item.xml
new file mode 100644
index 0000000..675980c
--- /dev/null
+++ b/samples/Support4Demos/src/main/res/layout/recycler_view_with_collapsing_toolbar_list_item.xml
@@ -0,0 +1,34 @@
+
+
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:padding="16dp"
+ android:focusable="true">
+
+
+ android:id="@+id/textViewHeader"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="24sp" />
+
+
+ android:id="@+id/textViewSubHeader"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="14sp" />
+
diff --git a/samples/Support4Demos/src/main/res/values/strings.xml b/samples/Support4Demos/src/main/res/values/strings.xml
index e9624cb..08b2848 100644
--- a/samples/Support4Demos/src/main/res/values/strings.xml
+++ b/samples/Support4Demos/src/main/res/values/strings.xml
@@ -244,6 +244,9 @@
regular
round
+ Widget/RecyclerView with Collapsing Appbar
+ Header
+
Not tint
Color tint
Color state list