Android/Java:如何从另一个 activity 访问我的 BottomNavigationView 特定变量?

Android/Java: How to access to my BottomNavigationView specific variables from another activity?

我想从 LocalNav 中的 NewBottomNav 访问变量 initialization,但我不知道如何访问它?

NewBottomNav class:

public final class newBottomNav extends BottomNavigationView {
    private final Context context;
    private Typeface fontFace = null;
    public static Integer initialization = 0;

...
}

本地导航Class:

public class LocalNav extends AppCompatActivity {
    Context mContext;
    WebView view;
    BottomNavigationView bottomNavigation;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        int size = bottomNavigation.getMenu().size();

        bottomNavigation.setOnNavigationItemSelectedListener (new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem Item) {

            bottomNavigation.initialization = 1; //<= How to access to initialization
...
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/relativeLayout3"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LocalNav">

    <WebView
        android:id="@+id/vieweb"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="0dp"
        android:layout_marginBottom="-2dp"
        app:layout_constraintBottom_toTopOf="@+id/bottom_nav"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <com.NewTelApps.ToEvent.newBottomNav
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        app:itemIconSize="45dp"
        android:visible="false"
        app:itemBackground="@drawable/nav_item_drawable"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_nav_menu"
        />


</androidx.constraintlayout.widget.ConstraintLayout>

我不知道如何访问它,因为它是一个 BottomNavigationView。有什么具体的事情要做吗?

提前致谢。

你只需要改变声明从

BottomNavigationView bottomNavigation;

newBottomNav bottomNavigation;

因为 initialization 没有在 BottomNavigationView

中定义