MAIN PAGE

PHOTO EMBED

Sat Jan 20 2024 14:23:02 GMT+0000 (Coordinated Universal Time)

Saved by @mehran

package com.verify724.blue_check;

import static android.app.PendingIntent.getActivity;

import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.etebarian.meowbottomnavigation.MeowBottomNavigation;


public class main_page extends AppCompatActivity {

    MeowBottomNavigation bottomNavigation;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_page);

        bottomNavigation = findViewById(R.id.bottomNav);

        bottomNavigation.add(new MeowBottomNavigation.Model(1,R.drawable.ic_home));

        bottomNavigation.add(new MeowBottomNavigation.Model(2,R.drawable.ic_home));
        bottomNavigation.add(new MeowBottomNavigation.Model(3,R.drawable.ic_home));


        final Fragment[] fragment = {null,null};
        //bottomNavigation.setCount(3,"5");

        bottomNavigation.setOnShowListener(new MeowBottomNavigation.ShowListener() {
            @Override
            public void onShowItem(MeowBottomNavigation.Model item) {

                if (item.getId() == 2){
                    fragment[0] = new HomeFragment();
                }

                loadFragment(fragment[0]);
            }
        });

        bottomNavigation.show(2,true);

        bottomNavigation.setOnClickMenuListener(new MeowBottomNavigation.ClickListener() {
            @Override
            public void onClickItem(MeowBottomNavigation.Model item) {
                //Toast.makeText(getApplicationContext(),"you "+item.getId(),Toast.LENGTH_SHORT);
                //Fragment fragment = null;
                if (item.getId() == 1){
                    fragment[1] = new btn_menu_it2();
                }
                removeFragment(fragment[0]);
                loadFragment(fragment[1]);
            }
        });
        bottomNavigation.setOnReselectListener(new MeowBottomNavigation.ReselectListener() {
            @Override
            public void onReselectItem(MeowBottomNavigation.Model item) {
                //Toast.makeText(getApplicationContext(),"you resel "+item.getId(),Toast.LENGTH_SHORT);
                if (item.getId() == 1){
                    fragment[1] = new btn_menu_it2();
                }
                removeFragment(fragment[0]);
                loadFragment(fragment[1]);
            }
        });


    }

    private void loadFragment(Fragment fragment) {
        getSupportFragmentManager().beginTransaction().replace(R.id.nav_host_fragment_container,fragment,null).commit();
    }

    public void removeFragment(Fragment fragment){
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        fragmentTransaction.remove(fragment);
        fragmentTransaction.commit();
    }

}
content_copyCOPY