如何在底部导航视图中放置选项卡式布局?

问题描述

我曾尝试使用下面的查看寻呼机代码,但代码崩溃了。我基本上需要在底部导航的 5 个选项卡式活动。你能不能告诉我我将如何使用片段中的选项卡式布局代码。谢谢你

public class client_interface_start extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       setContentView(R.layout.client_interface_start);
        BottomNavigationView bottomNav = findViewById(R.id.client_bottom_navigation);
        bottomNav.setonNavigationItemSelectedListener(navlistener1);

SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this,getSupportFragmentManager());
ViewPager viewPager = findViewById(R.id.client_viewpager);
viewPager.setAdapter(sectionsPagerAdapter);
TabLayout tabs = findViewById(R.id.client_tablayout_listings);
tabs.setupWithViewPager(viewPager);SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this,getSupportFragmentManager());
ViewPager viewPager = findViewById(R.id.client_viewpager);
viewPager.setAdapter(sectionsPagerAdapter);
TabLayout tabs = findViewById(R.id.client_tablayout_listings);
tabs.setupWithViewPager(viewPager);

        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_containerclient,new fragment_client_listings()).commit();

        }


    private BottomNavigationView.OnNavigationItemSelectedListener navlistener1 =
            new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    Fragment selectedFragment = null;
                    switch (item.getItemId()) {

                        case R.id.nav_clientlistings:
                            selectedFragment = new fragment_client_listings();
                            break;

                        case R.id.nav_clientrequest:
                            selectedFragment = new fragment_client_request();
                            break;
                        case R.id.nav_clientorders:
                            selectedFragment = new fragment_client_orders();
                            break;
                     case R.id.nav_clientprofile:
                            selectedFragment = new fragment_client_profile();
                           break;
                        case R.id.nav_clientnotifications:
                            selectedFragment = new fragment_client_notifications();
                            break;
                    }
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_containerclient,selectedFragment).commit();
                    return true;
                }
            };

    }

这是 XML 文件,我在其中有 3 个选项卡,列出了收藏夹和约会。我希望能够点击它们并为每个 TabItem 显示不同的布局片段。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout >

<com.google.android.material.appbar.AppBarLayout
  android:id="@+id/client_appbar_listings"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <com.google.android.material.tabs.TabLayout
        android:id="@+id/client_tablayout_listings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.material.tabs.TabItem
            android:id="@+id/client_listings_tab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Listings" />

        <com.google.android.material.tabs.TabItem
            android:id="@+id/client_favorites_tab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Favorites" />

        <com.google.android.material.tabs.TabItem
            android:id="@+id/client_appointments_tab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Appointments" />
    </com.google.android.material.tabs.TabLayout>

</com.google.android.material.appbar.AppBarLayout>


    <FrameLayout
        android:id="@+id/alerts_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/client_bottom_navigation"
        android:layout_marginTop="50dp" >

        <Button
            android:id="@+id/placement"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Placement profile " />

        <androidx.viewpager.widget.ViewPager
            android:id="@+id/client_viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/black"/>


    </FrameLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Client Listings"/>




</RelativeLayout>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...