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); + } }