From 1ce3af59e6dfc59a7d3af889276b193e358e8d4a Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 23 Jan 2024 05:22:48 +0900 Subject: [PATCH] =?UTF-8?q?UI=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/feature/home/HomeTopFragment.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java b/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java index 3d64657c..64c5434b 100644 --- a/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java +++ b/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java @@ -8,11 +8,14 @@ import android.view.View; import android.view.ViewGroup; import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.navigation.Navigation; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.appbar.AppBarLayout; + import javax.inject.Inject; import dagger.hilt.android.AndroidEntryPoint; @@ -56,6 +59,23 @@ public class HomeTopFragment extends Fragment { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_home_top, container, false); + // 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 + } + } + }); return view; }