CollapsingToolBar実装テスト

This commit is contained in:
ろむねこ 2024-01-19 15:45:18 +09:00
parent 9d2e5dd217
commit 5d8b9f338d
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
2 changed files with 44 additions and 18 deletions

View File

@ -6,10 +6,15 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import java.util.ArrayList;
import java.util.List;
@ -79,8 +84,7 @@ public class HomeTopFragment extends Fragment {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_home_top, container, false);
@ -100,8 +104,23 @@ public class HomeTopFragment extends Fragment {
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
CollapsingToolbarLayout collapsingToolbarLayout = view.findViewById(R.id.collapsing_toolbar);
Toolbar toolbar = view.findViewById(R.id.toolbar);
// Set the Toolbar
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
// Set the title of the CollapsingToolbarLayout
collapsingToolbarLayout.setTitle("Title");
}
}
String pageTitle;
String pageId;
ArrayList listItems;

View File

@ -1,21 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeTopFragment"
tools:ignore="ExtraText">
android:layout_height="match_parent">
<!-- TODO: Update blank fragment layout -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/item_recycler_view"
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
</androidx.recyclerview.widget.RecyclerView>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<!-- Your content here -->
</androidx.coordinatorlayout.widget.CoordinatorLayout>