【问题标题】:TABS Are not displayed in FragmentTABS 不显示在 Fragment 中
【发布时间】:2016-12-25 00:32:44
【问题描述】:

我无法理解为什么主要片段没有显示选项卡。我的代码没有任何错误,只是当我单击导航抽屉中的项目时,它没有显示带有标签的片段。 有人可以帮忙吗,谢谢你的时间,不胜感激。

主要片段代码

    package app.com.navigatemenu;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link MainFragment.OnFragmentInteractionListener} interface
 * to handle interaction events.
 * Use the {@link MainFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class MainFragment extends Fragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private FragmentTabHost mTabHost;


    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    private OnFragmentInteractionListener mListener;

    public MainFragment() {
        // Required empty public constructor
    }


    public static MainFragment newInstance(String param1, String param2) {
        MainFragment fragment = new MainFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }
/*
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_main, container, false);
    }
*/
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_main,container, false);


        mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
        mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);

        mTabHost.addTab(mTabHost.newTabSpec("fragmentc").setIndicator("Fragment C"),
                MovieFragment.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("fragmentb").setIndicator("Fragment B"),
                GalleryFragment.class, null);
        return rootView;
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.onFragmentInteraction(uri);
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnFragmentInteractionListener) {
            mListener = (OnFragmentInteractionListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }
}

主要活动代码

   package app.com.navact;

import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener, MainFragment.OnFragmentInteractionListener,
        FragmentA.OnFragmentInteractionListener, FragmentB.OnFragmentInteractionListener {

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

        MainFragment fragment = new MainFragment();
        android.support.v4.app.FragmentTransaction fragmentTransaction =
                getSupportFragmentManager().beginTransaction();
        fragmentTransaction.add(R.id.fragment_container, fragment);
        fragmentTransaction.commit();

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



        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.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);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_camera) {
            MainFragment fragment = new MainFragment();
            android.support.v4.app.FragmentTransaction fragmentTransaction =
                    getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(R.id.fragment_container, fragment);
            fragmentTransaction.commit();

            // Handle the camera action
        } else if (id == R.id.nav_gallery) {

        } else if (id == R.id.nav_slideshow) {

        } else if (id == R.id.nav_manage) {

        } else if (id == R.id.nav_share) {

        } else if (id == R.id.nav_send) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

    @Override
    public void onFragmentInteraction(Uri uri) {

    }
}

Fragment_main 布局

  <android.support.v4.app.FragmentTabHost
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <FrameLayout
                android:id="@+id/realtabcontent"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>

        </LinearLayout>
    </android.support.v4.app.FragmentTabHost>

Fragment_conatiner

<FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</FrameLayout>

片段容器的文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    tools:context="app.com.navact.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>


    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </FrameLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

【问题讨论】:

    标签: android android-fragments android-tabs


    【解决方案1】:

    改变

    <FrameLayout
                android:id="@+id/realtabcontent"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
    

    <FrameLayout
                android:id="@+id/realtabcontent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />
    

    请告诉我结果。

    【讨论】:

      【解决方案2】:

      在您执行任何此操作之前,请确保您已备份您的项目,因为我没有对此进行测试!!!

      内部协调布局fragment_container 我要你放置一个 FrameLayout 之前,确保它是 layout_heightwrap_content。我希望你使它的 id 等于 realtabcontent。我希望您将属性 layout_weight 添加到 fragment_container 并使其等于 1

      我要你删除片段主布局,确保你有这个项目的备份!!!

      内部主要片段

      我希望您将 onCreateView 更改为:

      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          mTabHost = new FragmentTabHost(getActivity());
          mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
          mTabHost.addTab(mTabHost.newTabSpec("fragmentc").setIndicator("Fragment C"), MovieFragment.class, null);
          mTabHost.addTab(mTabHost.newTabSpec("fragmentb").setIndicator("Fragment B"), GalleryFragment.class, null);
          return inflater.inflate(R.id.fragment_container, null);
      }
      

      【讨论】:

      • 评论不用于扩展讨论;这个对话是moved to chat
      • 所以我在 fragment_container 之前添加了你的代码在创建视图的主片段中......我运行了项目......我没有看到选项卡,但我在屏幕“画廊片段”上看到了文字。 .. 看起来像片段一样有效.. 但没有标签...
      【解决方案3】:

      主活动

               package app.com.navact;
                  import android.net.Uri;
                  import android.os.Bundle;
                  import android.support.design.widget.FloatingActionButton;
                  import android.support.design.widget.Snackbar;
                  import android.view.View;
                  import android.support.design.widget.NavigationView;
                  import android.support.v4.view.GravityCompat;
                  import android.support.v4.widget.DrawerLayout;
                  import android.support.v7.app.ActionBarDrawerToggle;
                  import android.support.v7.app.AppCompatActivity;
                  import android.support.v7.widget.Toolbar;
                  import android.view.Menu;
                  import android.view.MenuItem;
      
                  public class MainActivity extends AppCompatActivity
                          implements NavigationView.OnNavigationItemSelectedListener, MainFragment.OnFragmentInteractionListener
                          {
      
                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                          setContentView(R.layout.activity_main);
      
                          MainFragment fragment = new MainFragment();
                          android.support.v4.app.FragmentTransaction fragmentTransaction =
                                  getSupportFragmentManager().beginTransaction();
                          fragmentTransaction.replace(R.id.fragment_container, fragment);
                          fragmentTransaction.commit();
      
                          Toolbar toolbar = 
      
          (Toolbar) findViewById(R.id.toolbar);
                      setSupportActionBar(toolbar);
      
                      FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
                      fab.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                                      .setAction("Action", null).show();
                          }
                      });
      
                      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
                      ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                              this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
                      drawer.setDrawerListener(toggle);
                      toggle.syncState();
      
                      NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
                      navigationView.setNavigationItemSelectedListener(this);
                  }
      
                  @Override
                  public void onBackPressed() {
                      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
                      if (drawer.isDrawerOpen(GravityCompat.START)) {
                          drawer.closeDrawer(GravityCompat.START);
                      } else {
                          super.onBackPressed();
                      }
                  }
      
                  @Override
                  public boolean onCreateOptionsMenu(Menu menu) {
                      // Inflate the menu; this adds items to the action bar if it is present.
                      getMenuInflater().inflate(R.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);
                  }
      
                  @SuppressWarnings("StatementWithEmptyBody")
                  @Override
                  public boolean onNavigationItemSelected(MenuItem item) {
                      // Handle navigation view item clicks here.
                      int id = item.getItemId();
      
                      if (id == R.id.nav_camera) {
                          MainFragment fragment = new MainFragment();
                          android.support.v4.app.FragmentTransaction fragmentTransaction =
                                  getSupportFragmentManager().beginTransaction();
                          fragmentTransaction.replace(R.id.fragment_container, fragment);
                          fragmentTransaction.commit();
      
                          // Handle the camera action
                      } else if (id == R.id.nav_gallery) {
      
                      } else if (id == R.id.nav_slideshow) {
      
                      } else if (id == R.id.nav_manage) {
      
                      } else if (id == R.id.nav_share) {
      
                      } else if (id == R.id.nav_send) {
      
                      }
      
                      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
                      drawer.closeDrawer(GravityCompat.START);
                      return true;
                  }
      
                  @Override
                  public void onFragmentInteraction(Uri uri) {
      
                  }
              }
      

      主要片段

              package app.com.navact;
              import android.app.LocalActivityManager;
              import android.content.Context;
              import android.content.Intent;
              import android.net.Uri;
              import android.os.Bundle;
              import android.support.design.widget.TabLayout;
              import android.support.v4.app.Fragment;
              import android.support.v4.app.FragmentManager;
              import android.support.v4.app.FragmentPagerAdapter;
              import android.support.v4.app.FragmentTabHost;
              import android.support.v4.view.ViewPager;
              import android.view.LayoutInflater;
              import android.view.View;
              import android.view.ViewGroup;
      
      
              /**
               * A simple {@link Fragment} subclass.
               * Activities that contain this fragment must implement the
               * {@link MainFragment.OnFragmentInteractionListener} interface
               * to handle interaction events.
               * Use the {@link MainFragment#newInstance} factory method to
               * create an instance of this fragment.
               */
              public class MainFragment extends Fragment {
                  private static final String ARG_PARAM1 = "param1";
                  private static final String ARG_PARAM2 = "param2";
                  private String mParam1;
                  private String mParam2;
                  private FragmentTabHost mTabHost ;
      
                  private OnFragmentInteractionListener mListener;
                  public static TabLayout tabLayout;
                  public static ViewPager viewPager;
                  public static int int_items = 2 ;
      
                  public MainFragment() {
                      // Required empty public constructor
                  }
      
                  /**
                   * Use this factory method to create a new instance of
                   * this fragment using the provided parameters.
                   *
                   * @param param1 Parameter 1.
                   * @param param2 Parameter 2.
                   * @return A new instance of fragment MainFragment.
                   */
                  // TODO: Rename and change types and number of parameters
                  public static MainFragment newInstance(String param1, String param2) {
                      MainFragment fragment = new MainFragment();
                      Bundle args = new Bundle();
                      args.putString(ARG_PARAM1, param1);
                      args.putString(ARG_PARAM2, param2);
                      fragment.setArguments(args);
                      return fragment;
                  }
      
                  @Override
                  public void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
      
                      if (getArguments() != null) {
                          mParam1 = getArguments().getString(ARG_PARAM1);
                          mParam2 = getArguments().getString(ARG_PARAM2);
                      }
                  }
      
                  @Override
                  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                           Bundle savedInstanceState) {
      
                      View x =  inflater.inflate(R.layout.tab_layout,null);
                      tabLayout = (TabLayout) x.findViewById(R.id.tabs);
                      viewPager = (ViewPager) x.findViewById(R.id.viewpager);
                      viewPager.setAdapter(new MyAdapter(getChildFragmentManager()));
      
                      tabLayout.post(new Runnable() {
                          @Override
                          public void run() {
                              tabLayout.setupWithViewPager(viewPager);
                          }
                      });
      
                      return x;
                  }
      
                  // TODO: Rename method, update argument and hook method into UI event
                  public void onButtonPressed(Uri uri) {
                      if (mListener != null) {
                          mListener.onFragmentInteraction(uri);
                      }
                  }
      
                  @Override
                  public void onAttach(Context context) {
                      super.onAttach(context);
                      if (context instanceof OnFragmentInteractionListener) {
                          mListener = (OnFragmentInteractionListener) context;
                      } else {
                          throw new RuntimeException(context.toString()
                                  + " must implement OnFragmentInteractionListener");
                      }
                  }
      
                  class MyAdapter extends FragmentPagerAdapter {
      
                      public MyAdapter(FragmentManager fm) {
                          super(fm);
                      }
      
                      /**
                       * Return fragment with respect to Position .
                       */
      
                      @Override
                      public Fragment getItem(int position)
                      {
                          switch (position){
                              case 0 : return new TabFragment1();
                              case 1 : return new TabFragment2();
      
                          }
                          return null;
                      }
      
                      @Override
                      public int getCount() {
      
                          return int_items;
      
                      }
      
                      /**
                       * This method returns the title of the tab according to the position.
                       */
      
                      @Override
                      public CharSequence getPageTitle(int position) {
      
                          switch (position){
                              case 0 :
                                  return "TabFragMent1";
                              case 1 :
                                  return "TabFragment2";
      
                          }
                          return null;
                      }
                  }
      
      
                  @Override
                  public void onDetach() {
                      super.onDetach();
                      mListener = null;
                  }
      
      
                  public interface OnFragmentInteractionListener {
                      // TODO: Update argument type and name
                      void onFragmentInteraction(Uri uri);
                  }
              }
      

      标签布局

          <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout
              xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              android:layout_width="match_parent"
              android:orientation="vertical"
              android:layout_height="wrap_content">
      
      
              <android.support.design.widget.TabLayout
                  android:id="@+id/tabs"
                  android:background="@android:color/holo_orange_dark"
                  app:tabIndicatorColor="@color/colorAccent"
                   app:tabSelectedTextColor="@android:color/holo_blue_bright"
                  app:tabTextColor="@color/colorPrimaryDark"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">
              </android.support.design.widget.TabLayout>
      
      
              <android.support.v4.view.ViewPager
                  android:id="@+id/viewpager"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent">
              </android.support.v4.view.ViewPager>
      
      
      
          </LinearLayout>
      

      标签活动1

              package app.com.navact;
      
              import android.content.Context;
              import android.net.Uri;
              import android.os.Bundle;
              import android.support.v4.app.Fragment;
              import android.view.LayoutInflater;
              import android.view.View;
              import android.view.ViewGroup;
      
      
      
      
              public class TabFragment1 extends Fragment {
                      @Override
                      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                          return inflater.inflate(R.layout.fragment_tab_fragment1, container, false);
                      }
      
              }
      

      TabActivity2

              package app.com.navact;
      
              import android.content.Context;
              import android.net.Uri;
              import android.os.Bundle;
              import android.support.v4.app.Fragment;
              import android.view.LayoutInflater;
              import android.view.View;
              import android.view.ViewGroup;
      
      
              public class TabFragment2 extends Fragment {
      
                  @Override
                  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                      return inflater.inflate(R.layout.fragment_tab_fragment2, container, false);
                  }
              }
      

      tab1 布局

              <?xml version="1.0" encoding="utf-8"?>
              <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical" android:layout_width="match_parent"
                  android:layout_height="match_parent">
      
                  <TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_marginTop="40dp"
                      android:textSize="30sp"
                      android:gravity="center"
                      android:id="@+id/textView"
                      android:layout_centerHorizontal="true"
                      android:textColor="@android:color/holo_blue_dark"
                      android:text="Primary\nFragment"/>
      
                  <TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:autoLink="web"
                      android:textSize="15sp"
                      android:layout_marginTop="10dp"
                      android:layout_centerHorizontal="true"
                      android:text="androidbelieve.com"
                      android:textColor="#000"
                      android:layout_below="@+id/textView"
                      android:textStyle="italic"/>
      
              </RelativeLayout>
      

      tab2布局

              <?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"
                  android:orientation="vertical">
      
                  <TextView
                      android:id="@+id/textView"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_centerInParent="true"
                      android:text="Tab 2"
                      android:textAppearance="?android:attr/textAppearanceLarge"/>
      
              </RelativeLayout>
      

      应用构建 Gradle

              apply plugin: 'com.android.application'
      
              android {
                  compileSdkVersion 25
                  buildToolsVersion "25.0.1"
                  defaultConfig {
                      applicationId "app.com.navact"
                      minSdkVersion 19
                      targetSdkVersion 25
                      versionCode 1
                      versionName "1.0"
                      testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
                  }
                  buildTypes {
                      release {
                          minifyEnabled false
                          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                      }
                  }
              }
      
              dependencies {
                  compile fileTree(dir: 'libs', include: ['*.jar'])
                  androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
                      exclude group: 'com.android.support', module: 'support-annotations'
                  })
                  compile 'com.android.support:appcompat-v7:25.1.0'
                  compile 'com.android.support:design:25.1.0'
                  compile 'com.android.support:support-v4:25.1.0'
                  testCompile 'junit:junit:4.12'
                  compile 'com.android.support:recyclerview-v7:25.1.0'
              }
      

      【讨论】:

      • 我花了 10 个小时才找到这个解决方案,这是片段内的滑动标签,与导航抽屉集成....现在凌晨 3 点,我正在睡觉...这是我的回馈社区......欢呼和圣诞快乐...... :)
      • 请不要把你的整个项目丢在这里——试着把解决方案解释为minimal reproducible example
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-21
      • 1970-01-01
      • 2014-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      相关资源
      最近更新 更多