Android layout 如何使选项卡仅对其中一个导航抽屉项可见?

Android layout 如何使选项卡仅对其中一个导航抽屉项可见?,android-layout,android-studio,navigation-drawer,android-fragmentactivity,android-tabs,Android Layout,Android Studio,Navigation Drawer,Android Fragmentactivity,Android Tabs,我是android开发的新手,当时正在尝试构建一个带有导航抽屉和选项卡视图的应用程序。我指的是 来构建代码。我设法建立了一个登录页面,这将导致另一个活动页面。在这里,我面临一个问题。我只想要“家”抽屉项目的标签,而不是抽屉项目的其余部分 导航抽屉输出正常 而且它是可点击的。我在网上提到过,但无法缩小范围,找到任何解决方案 activity_main2.xml(选项卡集成和导航抽屉): 对于代码 这是我的“主”片段xml文件(朋友和消息的格式相同) 这是我的一个xml文件: &

我是android开发的新手,当时正在尝试构建一个带有导航抽屉和选项卡视图的应用程序。我指的是 来构建代码。我设法建立了一个登录页面,这将导致另一个活动页面。在这里,我面临一个问题。我只想要“家”抽屉项目的标签,而不是抽屉项目的其余部分

导航抽屉输出正常

而且它是可点击的。我在网上提到过,但无法缩小范围,找到任何解决方案

activity_main2.xml(选项卡集成和导航抽屉):


对于代码

这是我的“主”片段xml文件(朋友和消息的格式相同)


这是我的一个xml文件:

     <?xml version="1.0" encoding="utf-8"?>
       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.example.arunrony.myapplication_trial.OneFragment">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="One_tab"
    android:textSize="40dp"
    android:textStyle="bold"
    android:layout_centerInParent="true"/>

      </RelativeLayout>


我忘了添加构建导航抽屉的教程。请帮忙,我真的需要帮忙
package com.example.arunrony.myapplication_trial;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import java.util.List;
import java.util.ArrayList;
import android.support.design.widget.TabLayout;

    import android.widget.Toast;
    import com.example.arunrony.myapplication_trial.R;
        public class Main2Activity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener {

private static String TAG = Main2Activity.class.getSimpleName();
private Toolbar mToolbar;
private FragmentDrawer drawerFragment;
private TabLayout tabLayout;
private ViewPager viewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    drawerFragment = (FragmentDrawer)
            getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
    drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
    drawerFragment.setDrawerListener(this);
    // display the first navigation drawer view on app launch
    displayView(1);
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
}
private void setupViewPager(ViewPager viewPager) {
    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(new OneFragment(), "ONE");
    adapter.addFragment(new TwoFragment(), "TWO");
    viewPager.setAdapter(adapter);
}

class ViewPagerAdapter extends FragmentPagerAdapter {
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFragment(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position);
    }
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onDrawerItemSelected(View view, int position) {
    displayView(position);
}

private void displayView(int position) {
    Fragment fragment = null;
    String title = getString(R.string.app_name);
    switch (position) {
        case 0:
            fragment = new HomeFragment();
            title = getString(R.string.title_home);
            break;
        case 1:
            fragment = new FriendsFragment();
            title = getString(R.string.title_friends);
            break;
        case 2:
            fragment = new MessagesFragment();
            title = getString(R.string.title_messages);
            break;
        default:
            break;
    }

    if (fragment != null) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.container_body, fragment);
        fragmentTransaction.commit();

        // set the toolbar title
        getSupportActionBar().setTitle(title);
    }

}
}
<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.arunrony.myapplication_trial">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/MyMaterialTheme">
    <activity
        android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:label="@string/app_name"
        android:name=".Main2Activity" />
</application>

</manifest>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context="com.example.arunrony.myapplication_trial.HomeFragment">
<TextView
    android:id="@+id/label"
    android:layout_alignParentTop="true"
    android:layout_marginTop="100dp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:textSize="45dp"
    android:text="HOME"
    android:textStyle="bold"/>

<TextView
    android:layout_below="@id/label"
    android:layout_centerInParent="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="12dp"
    android:layout_marginTop="10dp"
    android:gravity="center_horizontal"
    android:text="Edit fragment_home.xml to change the appearance" />

                   </RelativeLayout>
     <?xml version="1.0" encoding="utf-8"?>
       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.example.arunrony.myapplication_trial.OneFragment">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="One_tab"
    android:textSize="40dp"
    android:textStyle="bold"
    android:layout_centerInParent="true"/>

      </RelativeLayout>