ステータスバーの色を合わせる処理を移植

This commit is contained in:
ろむねこ 2024-01-22 18:18:12 +09:00
parent 3b684bec53
commit 20828e2f0f
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
2 changed files with 20 additions and 1 deletions

View File

@ -150,6 +150,25 @@ public class LibraryPageFragment extends Fragment {
this.currentTotalItemCount = libraryItemPage.getListItems().size(); this.currentTotalItemCount = libraryItemPage.getListItems().size();
}); });
} }
// Set status bar color
AppBarLayout appBarLayout = view.findViewById(R.id.app_bar_layout);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (Math.abs(verticalOffset) == appBarLayout.getTotalScrollRange()) {
// Collapsed
getActivity().getWindow().setStatusBarColor(ContextCompat.getColor(getContext(), one.nem.lacerta.shared.ui.R.color.colorSecondaryContainer));
} else if (verticalOffset == 0) {
// Expanded
getActivity().getWindow().setStatusBarColor(ContextCompat.getColor(getContext(), one.nem.lacerta.shared.ui.R.color.colorSurface));
} else {
// Somewhere in between
// Here you can add a color transition if you want
}
}
});
} }
@Override @Override

View File

@ -29,7 +29,7 @@
app:layout_scrollFlags="scroll|exitUntilCollapsed"> app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/library_toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" app:layout_collapseMode="pin"