From 05997eafe17d177c3c443a99c54a88843a3e2abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 11:26:11 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=95=E3=83=A9=E3=82=B0=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=81=8B=E3=82=89ToolBar=E3=81=AE=E3=82=A2=E3=82=A4?= =?UTF-8?q?=E3=83=86=E3=83=A0=E3=82=92=E5=88=B6=E5=BE=A1=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/MainActivity.java | 36 +++++++++++++++++++ .../lacerta/feature/home/HomeTopFragment.java | 8 +++++ 2 files changed, 44 insertions(+) diff --git a/app/src/main/java/one/nem/lacerta/MainActivity.java b/app/src/main/java/one/nem/lacerta/MainActivity.java index 84d15b35..66985ad0 100644 --- a/app/src/main/java/one/nem/lacerta/MainActivity.java +++ b/app/src/main/java/one/nem/lacerta/MainActivity.java @@ -1,6 +1,7 @@ package one.nem.lacerta; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.fragment.app.FragmentManager; import androidx.navigation.NavController; @@ -17,6 +18,7 @@ import android.widget.Toast; import one.nem.lacerta.model.pref.FeatureSwitchOverride; import one.nem.lacerta.utils.FeatureSwitch; +import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.bottomnavigation.BottomNavigationView; @@ -68,6 +70,40 @@ public class MainActivity extends AppCompatActivity { // Set status bar color getWindow().setStatusBarColor(ContextCompat.getColor(this, one.nem.lacerta.shared.ui.R.color.colorSurface)); + + // Set app bar color + AppBarLayout appBarLayout = 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 + getWindow().setStatusBarColor(ContextCompat.getColor(getApplicationContext(), one.nem.lacerta.shared.ui.R.color.colorSecondaryContainer)); + } else if (verticalOffset == 0) { + // Expanded + getWindow().setStatusBarColor(ContextCompat.getColor(getApplicationContext(), one.nem.lacerta.shared.ui.R.color.colorSurface)); + } else { + // Somewhere in between + // Here you can add a color transition if you want + } + } + }); + + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + } + + // Public + public void setActionBarTitle(String title) { + getSupportActionBar().setTitle(title); + } + + public void setActionBarBackButton(boolean isEnabled) { + getSupportActionBar().setDisplayHomeAsUpEnabled(isEnabled); + } + + public void setActionBarMenuItem(int itemId, boolean isEnabled) { + } private void initializeApp() { 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 6070f726..a5d26c13 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 @@ -10,6 +10,7 @@ import android.view.View; import android.view.ViewGroup; +import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; @@ -70,6 +71,7 @@ public class HomeTopFragment extends Fragment { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_home_top, container, false); + setHasOptionsMenu(true); return view; } @@ -96,6 +98,12 @@ public class HomeTopFragment extends Fragment { }); }); } + + @Override + public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { + inflater.inflate(R.menu.drawer_menu, menu); + super.onCreateOptionsMenu(menu, inflater); + } }