Создание значка в Android Studio 2022.1.1 Patch 2 с нижней панелью навигации и навигационным компонентом etpack с использованием Material Design 3
«Привет всем! Сегодня я рад поделиться своим захватывающим личным путешествием. Начиная свой проект приложения, я столкнулся с трудностями при попытке создать значок в Android Studio с Material Design 3. но, в конце концов, мне удалось преодолеть все препятствия. Я здесь, чтобы поделиться с вами, как я это сделал!" примеры:введите сюда описание изображения
// This is the onStart method.
// It's used in the lifecycle of an activity to perform setups and preparations
// before the activity becomes visible to the user.
@Override
protected void onStart() {
super.onStart();
// Set up navigation and other UI elements here
// This is done before the activity is fully visible to the user
// to ensure everything is ready when it's displayed on the screen.
// You can set up event listeners, start services, etc.
// This is useful when you need certain actions to be performed before
// the user can interact with the activity.
}
// This is the onCreate method, which is called after onStart.
// Here, the initial setup of the activity is done, like configuring the UI and preparing data.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Other initial configurations can be done here.
}
полный код
`@Override
protected void onStart() {
super.onStart();
// Set up navigation controller for the bottom navigation view
NavController navController = Navigation.findNavController(this, R.id.fragmentContainerView);
NavigationUI.setupWithNavController(bottomNavigationView, navController, false);
// Set up navigation controller for the navigation drawer
NavController navControllerDrawer = Navigation.findNavController(this, R.id.fragmentContainerView);
NavigationUI.setupWithNavController(navigationView, navControllerDrawer, false);
// Handle item selection in the bottom navigation view
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@SuppressLint("NonConstantResourceId")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_inicio_op:
navController.navigate(R.id.nav_inicio_op);
break;
case R.id.nav_observacion_op:
navController.navigate(R.id.nav_observacion_op);
break;
case R.id.nav_trabajadores_op:
// Create and configure a badge for the "nav_trabajadores_op" item
BadgeDrawable badgeDrawable = bottomNavigationView.getOrCreateBadge(R.id.nav_trabajadores_op);
badgeDrawable.clearNumber();
badgeDrawable.setVisible(false);
// Navigate to the "nav_trabajadores_op" destination
navController.navigate(R.id.nav_trabajadores_op);
break;
case R.id.nav_usuario_op:
navController.navigate(R.id.nav_usuario_op);
break;
}
return false;
}
});
// Create and configure a counter view in the navigation drawer
LayoutInflater li = LayoutInflater.from(getApplicationContext());
tv_gallery_cunter = (TextView) li.inflate(R.layout.counter_gallery, null);
navigationView.getMenu().findItem(R.id.nav_observacion_op).setActionView(tv_gallery_cunter);
// Show the counter with a specific count number
Show_Counter(gallery_count_number);
}
// Crear y configurar una vista de contador en el menú desplegable de navegación (navigationView)
LayoutInflater li = LayoutInflater.from(getApplicationContext());
tv_gallery_cunter = (TextView) li.inflate(R.layout.counter_gallery, null);
navigationView.getMenu().findItem(R.id.nav_observacion_op).setActionView(tv_gallery_cunter);
// Mostrar el contador con un número específico
Show_Counter(gallery_count_number);
}`