mirror of
				https://github.com/lacerta-doc/Lacerta.git
				synced 2025-10-31 07:20:48 +00:00 
			
		
		
		
	フラグメントからToolBarのアイテムを制御できるようにした
This commit is contained in:
		
							parent
							
								
									d6f4885b4a
								
							
						
					
					
						commit
						05997eafe1
					
				| @ -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() { | ||||
|  | ||||
| @ -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); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user