底部按钮

fragment布局




    

        

            

                

                    

                    
                
            


            
        
    

news_activity

public class NewsActivity extends BaseActivity {
    private DrawerLayout news_drawer;
    private RadioGroup news_radio;
    private NavigationView news_nav;

    @Override
    public void initView() {
        news_radio = findViewById(R.id.news_radio);
        news_nav = findViewById(R.id.news_nav);
        news_drawer = findViewById(R.id.news_drawer);
    }

    @Override
    public void setView() {
        setFragment(new Fragment_Home());
    }

    @Override
    public int getLayout() {
        return R.layout.activity_news;
    }

    @Override
    public void setLinstener() {
        news_radio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.radio1:
                        setFragment(new Fragment_Home());
                        break;
                    case R.id.radio2:
                        setFragment(new Fragment_Find());
                        break;
                    case R.id.radio3:
                        setFragment(new Fragment_Self());
                        break;
                }
            }
        });
        news_nav.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.nav_item1:
                        Toast.makeText(NewsActivity.this, "nav_item1", Toast.LENGTH_SHORT).show();
                        news_drawer.closeDrawers();
                        break;
                    case R.id.nav_item2:
                        Toast.makeText(NewsActivity.this, "nav_item2", Toast.LENGTH_SHORT).show();
                        news_drawer.closeDrawers();
                        break;
                    case R.id.nav_item3:
                        Toast.makeText(NewsActivity.this, "nav_item3", Toast.LENGTH_SHORT).show();
                        news_drawer.closeDrawers();
                        break;
                    case R.id.nav_item4:
                        Toast.makeText(NewsActivity.this, "nav_item4", Toast.LENGTH_SHORT).show();
                        news_drawer.closeDrawers();
                        break;
                    case R.id.nav_item5:
                        Toast.makeText(NewsActivity.this, "nav_item5", Toast.LENGTH_SHORT).show();
                        news_drawer.closeDrawers();
                        break;
                }
                return false;
            }
        });
    }

    private void setFragment(Fragment fragment) {
        getSupportFragmentManager().beginTransaction().replace(R.id.news_frame, fragment).commit();
    }
}

你可能感兴趣的:(咨询项目实战)