Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bottom Navigation Bar(activity_main.xml, MainActivity.java) ____ 참고 #5

Open
honghyoeun opened this issue Apr 4, 2023 · 1 comment

Comments

@honghyoeun
Copy link
Contributor

No description provided.

@honghyoeun
Copy link
Contributor Author

  1. Bottom Navigation Bar __ activity_main.xml
    image
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <FrameLayout
        android:layout_width="match_parent"
        android:id="@+id/frameLayout"
        android:layout_above="@+id/btnNav"
        android:layout_alignParentBottom="true"
        android:layout_height="match_parent" />




    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="match_parent"
        android:id="@+id/btnNav"
        app:menu="@menu/menu"
        android:layout_alignParentBottom="true"
        android:layout_height="wrap_content"
        />


</RelativeLayout>
  1. MainActivity.java
package com.example.bottomnavigatoin;

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

import android.os.Bundle;
import android.view.MenuItem;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;

public class MainActivity extends AppCompatActivity {

    BottomNavigationView bottomNavigationView;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bottomNavigationView = findViewById(R.id.btnNav);


        fragementRepl(new HomeFragment());





        bottomNavigationView.setOnItemReselectedListener(new NavigationBarView.OnItemReselectedListener() {
            @Override
            public void onNavigationItemReselected(@NonNull MenuItem item) {

                switch ( item.getItemId()) {
                    case R.id.home:

                        fragementRepl(new HomeFragment());
                    break;

                    case R.id.chatting:

                        fragementRepl(new ChattingFragment());

                        break;

                    case R.id.favorite:

                        fragementRepl(new FavoriteFragment());

                        break;

                    case R.id.user:

                        fragementRepl(new UserFragment());

                        break;



                }


            }
        });
    }

    private void fragementRepl(Fragment fragment) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.frameLayout,fragment);
        fragmentTransaction.commit();

    }




}

@honghyoeun honghyoeun changed the title Bottom Navigation Bar Bottom Navigation Bar(activity_main.xml, MainActivity.java) Apr 4, 2023
@honghyoeun honghyoeun changed the title Bottom Navigation Bar(activity_main.xml, MainActivity.java) Bottom Navigation Bar(activity_main.xml, MainActivity.java) ____ 참고 Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant