• 团队冲刺第4天


    由于自己写的控件无法实现衔接流畅,所以改用Android自带的    BottomNavigationView+Fragment   导航栏

    步骤:

    1添加依赖:

    implementation 'com.google.android.material:material:1.2.1'

    2.布局文件:

    active_homepage.xml

    3.菜单

    <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item
            android:id="@+id/navigation_home"
            android:icon="@drawable/home"
            android:title="@string/title_home" />
    
        <item
            android:id="@+id/navigation_dashboard"
            android:icon="@drawable/billine"
            android:title="@string/title_dashboard" />
    
        <item
            android:id="@+id/navigation_notifications"
            android:icon="@drawable/message"
            android:title="@string/title_notifications" />
    
    </menu>

    4.activity及fragment代码

    package com.e.recily;
    
    import android.os.Bundle;
    import android.view.MenuItem;
    import android.widget.TextView;
    
    import com.google.android.material.bottomnavigation.BottomNavigationView;
    
    import androidx.annotation.NonNull;
    import androidx.appcompat.app.AppCompatActivity;
    import androidx.navigation.NavController;
    import androidx.navigation.Navigation;
    import androidx.navigation.ui.AppBarConfiguration;
    import androidx.navigation.ui.NavigationUI;
    
    public class HomepageActivity extends AppCompatActivity {
        private TextView mTextMessage;
        private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItenSelectedLister=new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                switch (menuItem.getItemId()) {
                    case R.id.navigation_home:
                        mTextMessage.setText(R.string.title_home);
                        return true;
                    case R.id.navigation_dashboard:
                        mTextMessage.setText(R.string.title_dashboard);
                        return true;
                    case R.id.navigation_notifications:
                        mTextMessage.setText(R.string.title_notifications);
                        return true;
                }
                return false;
            }
        };
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_homepage);
            mTextMessage=findViewById(R.id.message);
            BottomNavigationView navView = findViewById(R.id.nav_view);
    
    
            // Passing each menu ID as a set of Ids because each
            // menu should be considered as top level destinations.
            AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                    R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
                    .build();
            NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
            NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
            NavigationUI.setupWithNavController(navView, navController);
        }
    
    }
  • 相关阅读:
    CentOS 6.5 zabbix 3.0.4 乱码问题
    CentOS-6.5安装zabbix 3.0.4
    NFS工作原理及配置文件详解
    CentOS-6.5-NFS部署
    Swift中简单的单例设计
    UITableViewCell实现3D缩放动画
    Swift
    Swift
    [转]Swift编程风格指南
    pch文件出现no such file or directory错误
  • 原文地址:https://www.cnblogs.com/zyljal/p/14892042.html
Copyright © 2020-2023  润新知