Search in sources :

Example 1 with NavigationBarView

use of com.google.android.material.navigation.NavigationBarView in project luckyzyxtools by luckyzyx.

the class MainActivity method initBottomNavigationView.

// 初始化BottomNavigationView底部导航栏
@SuppressLint("NonConstantResourceId")
private void initBottomNavigationView() {
    NavigationBarView navigationBarView = findViewById(R.id.nav_item);
    // 设置监听方法_NavigationItem被选择事件
    navigationBarView.setOnItemSelectedListener(item -> {
        switch(item.getItemId()) {
            case R.id.nav_item_home:
                switchFragment(homeFragment);
                break;
            case R.id.nav_item_other:
                switchFragment(otherFragment);
                break;
            case R.id.nav_item_user:
                switchFragment(userFragment);
                break;
        }
        return true;
    });
    // 设置默认选中item
    switchFragment(homeFragment);
    // 设置默认选中item
    navigationBarView.setSelectedItemId(R.id.nav_item_home);
    // 设置选中显示label
    navigationBarView.setLabelVisibilityMode(NavigationBarView.LABEL_VISIBILITY_SELECTED);
}
Also used : NavigationBarView(com.google.android.material.navigation.NavigationBarView) SuppressLint(android.annotation.SuppressLint)

Example 2 with NavigationBarView

use of com.google.android.material.navigation.NavigationBarView in project LSPosed by naicfeng.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    if (savedInstanceState == null) {
        savedInstanceState = getIntent().getBundleExtra(EXTRA_SAVED_INSTANCE_STATE);
    }
    super.onCreate(savedInstanceState);
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    repoLoader.addListener(this);
    moduleUtil.addListener(this);
    onModulesReloaded();
    NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
    if (navHostFragment == null) {
        return;
    }
    NavController navController = navHostFragment.getNavController();
    var nav = (NavigationBarView) binding.nav;
    NavigationUI.setupWithNavController(nav, navController);
    handleIntent(getIntent());
}
Also used : NavigationBarView(com.google.android.material.navigation.NavigationBarView) NavController(androidx.navigation.NavController) NavHostFragment(androidx.navigation.fragment.NavHostFragment)

Example 3 with NavigationBarView

use of com.google.android.material.navigation.NavigationBarView in project vTunnel by net-byte.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    setContentView(R.layout.activity_main);
    NavigationBarView navigationView = findViewById(R.id.navigation_menu);
    navigationView.setOnItemSelectedListener(selectedListener);
    HomeFragment fragment = new HomeFragment();
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.content, fragment, "");
    fragmentTransaction.commit();
}
Also used : StrictMode(android.os.StrictMode) NavigationBarView(com.google.android.material.navigation.NavigationBarView) FragmentTransaction(androidx.fragment.app.FragmentTransaction) HomeFragment(com.netbyte.vtunnel.fragment.HomeFragment)

Example 4 with NavigationBarView

use of com.google.android.material.navigation.NavigationBarView in project LSPosed by LSPosed.

the class MainActivity method handleIntent.

private void handleIntent(Intent intent) {
    if (intent == null) {
        return;
    }
    NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
    if (navHostFragment == null) {
        return;
    }
    NavController navController = navHostFragment.getNavController();
    var nav = (NavigationBarView) binding.nav;
    if (intent.getAction() != null && intent.getAction().equals("android.intent.action.APPLICATION_PREFERENCES")) {
        nav.setSelectedItemId(R.id.settings_fragment);
    } else if (ConfigManager.isBinderAlive()) {
        if (!TextUtils.isEmpty(intent.getDataString())) {
            switch(intent.getDataString()) {
                case "modules":
                    nav.setSelectedItemId(R.id.modules_nav);
                    break;
                case "logs":
                    nav.setSelectedItemId(R.id.logs_fragment);
                    break;
                case "repo":
                    if (ConfigManager.isMagiskInstalled()) {
                        nav.setSelectedItemId(R.id.repo_nav);
                    }
                    break;
                case "settings":
                    nav.setSelectedItemId(R.id.settings_fragment);
                    break;
                default:
                    var data = intent.getData();
                    if (data != null && data.getScheme().equals("module")) {
                        navController.navigate(new Uri.Builder().scheme("lsposed").authority("module").appendQueryParameter("modulePackageName", data.getHost()).appendQueryParameter("moduleUserId", String.valueOf(data.getPort())).build(), new NavOptions.Builder().setEnterAnim(R.anim.fragment_enter).setExitAnim(R.anim.fragment_exit).setPopEnterAnim(R.anim.fragment_enter_pop).setPopExitAnim(R.anim.fragment_exit_pop).setLaunchSingleTop(true).setPopUpTo(navController.getGraph().getStartDestinationId(), false, true).build());
                    }
            }
        }
    }
}
Also used : NavigationBarView(com.google.android.material.navigation.NavigationBarView) NavOptions(androidx.navigation.NavOptions) NavController(androidx.navigation.NavController) NavHostFragment(androidx.navigation.fragment.NavHostFragment) Uri(android.net.Uri)

Example 5 with NavigationBarView

use of com.google.android.material.navigation.NavigationBarView in project LSPosed by LSPosed.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    if (savedInstanceState == null) {
        savedInstanceState = getIntent().getBundleExtra(EXTRA_SAVED_INSTANCE_STATE);
    }
    super.onCreate(savedInstanceState);
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    repoLoader.addListener(this);
    moduleUtil.addListener(this);
    onModulesReloaded();
    NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
    if (navHostFragment == null) {
        return;
    }
    NavController navController = navHostFragment.getNavController();
    var nav = (NavigationBarView) binding.nav;
    NavigationUI.setupWithNavController(nav, navController);
    handleIntent(getIntent());
}
Also used : NavigationBarView(com.google.android.material.navigation.NavigationBarView) NavController(androidx.navigation.NavController) NavHostFragment(androidx.navigation.fragment.NavHostFragment)

Aggregations

NavigationBarView (com.google.android.material.navigation.NavigationBarView)6 NavController (androidx.navigation.NavController)4 NavHostFragment (androidx.navigation.fragment.NavHostFragment)4 Uri (android.net.Uri)2 NavOptions (androidx.navigation.NavOptions)2 SuppressLint (android.annotation.SuppressLint)1 StrictMode (android.os.StrictMode)1 FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 HomeFragment (com.netbyte.vtunnel.fragment.HomeFragment)1