【问题标题】:Open activity from BottomNavigationView for Android从 BottomNavigationView 打开 Activity for Android
【发布时间】:2018-08-02 22:53:26
【问题描述】:

标题可能有误,抱歉。 我使用底部导航视图。当我单击一个图标时,我想打开一个不同的活动。我的部分代码如下,这段代码运行良好。

mainactiyity.java

 case R.id.navigation_home:
       Intent Intent = new Intent(getApplicationContext(), SetData.class);
       startActivity(Intent);
       return true;

SetData.java

    super.onCreate(savedInstanceState);
    setContentView(R.layout.set_data);

但我想在 BottomNavigationView 下打开新活动。新活动覆盖了整个屏幕,我看不到导航栏。我该如何解决?

activity.main

<android.support.constraint.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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="oww.MainActivity">

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    android:background="?android:attr/windowBackground"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:menu="@menu/navigation" />

</android.support.constraint.ConstraintLayout>

设置数据

<android.support.percent.PercentRelativeLayout

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"
android:background="@color/colorAccent"
tools:context=".SetData">

</android.support.percent.PercentRelativeLayout>

【问题讨论】:

    标签: android android-layout android-fragments layout bottomnavigationview


    【解决方案1】:

    您需要打开一个 Fragment 而不是 Activity。

    查看此博客了解如何操作

    https://segunfamisa.com/posts/bottom-navigation-view-android

    【讨论】:

    • 谢谢,我知道片段,但我需要在这个项目中打开活动。
    • 因此,唯一的方法是在您要从BottomNavigationView 打开的所有活动中使用BottomNavigationView,并在每个活动中检查您想要的选项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-19
    • 1970-01-01
    • 2016-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-10
    相关资源
    最近更新 更多