我已经使startactivity运行良好,登录/注册活动也正常工作,并更新了我所做的更改。但是所有其他5个有底部导航视图的布局根本没有更新。我已经试着找出这个问题好几个小时了,我不知道问题出在哪里。
Jmeter 板活动:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragments.Dashboard"
>
<!--Middlesection(body)-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
<include layout="@layout/texts_layout_tab"
/>
<!--bottomnavigation-->
<include
layout="@layout/layout_bottom_navigation_view"
/>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
摄像机:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
</RelativeLayout>
家庭:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include layout="@layout/texts_layout_tab" />
<!--bottomnavigation-->
<include layout="@layout/layout_bottom_navigation_view" />
</RelativeLayout>
轮廓:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
</RelativeLayout>
搜索:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".Search">
<com.google.android.material.appbar.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/bar"
android:background="?android:attr/windowBackground"
>
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:contentDescription="@string/search_bar"
android:src="@drawable/ic_search" />
<EditText
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:importantForAutofill="no"
android:textColor="@color/white"
android:hint="@string/hint_search"
android:inputType="text" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/bar"
android:id="@+id/recycler_view"/>
</RelativeLayout>
Bottom navigation view layout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavViewBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:itemIconTint="@color/white"
app:itemTextColor="#FFFFFF"
app:menu="@menu/bottom_navigation_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>
底部导航视图辅助对象:
public class BottomNavigationViewHelper extends AppCompatActivity {
private static final String TAG = "BottomNavigationViewHel";
Fragment selectFragment = null;
BottomNavigationView bottomNavigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_bottom_navigation_view);
bottomNavigationView = findViewById(R.id.bottomNavViewBar);
bottomNavigationView.setOnNavigationItemReselectedListener (navigationItemSelectListener);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new Profile()).commit();
}
private BottomNavigationView.OnNavigationItemReselectedListener navigationItemSelectListener =
new BottomNavigationView.OnNavigationItemReselectedListener() {
@Override
public void onNavigationItemReselected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.ic_dashboard:
selectFragment = null;
startActivity(new Intent(BottomNavigationViewHelper.this, Dashboard.class));
break;
case R.id.ic_home:
selectFragment = null;
startActivity(new Intent(BottomNavigationViewHelper.this, Home.class));
break;
case R.id.ic_camera:
selectFragment = null;
startActivity(new Intent(BottomNavigationViewHelper.this, Camera.class));
break;
case R.id.ic_search:
selectFragment = new Search();
break;
case R.id.ic_profile:
SharedPreferences.Editor editor = getSharedPreferences("PREPS", MODE_PRIVATE).edit();
editor.putString("profileid", Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid());
editor.apply();
selectFragment = new Profile();
}
if (selectFragment != null){
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, selectFragment).commit();
}
return;
}
};
}
暂无答案!
目前还没有任何答案,快来回答吧!