滑动菜单不会显示标签

时间:2015-05-19 00:45:06

标签: android material-design slidingmenu

我是Android的新手,我正在尝试实现滑动菜单,因此我按照一些教程进行了操作,最后得到了这些代码:

的活动:

public class MercadoriaFormActivity extends AbstractActivity {

@Inject
MercadoriaService mercadoriaService;

@InjectView(R.id.toolbarMercadoria)
Toolbar toolbar;

@InjectView(R.id.pagerMercadoriaForm)
ViewPager pager;

@InjectView(R.id.tabsMercadoria)
SlidingTabLayout tabs;

private MercadoriaFragmentPageAdapter adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_form_mercadoria);
    setSupportActionBar(toolbar);
    adapter = new MercadoriaFragmentPageAdapter(getSupportFragmentManager());
    pager.setAdapter(adapter);

    tabs.setDistributeEvenly(true);
    tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
        @Override
        public int getIndicatorColor(int position) {
            return getResources().getColor(R.color.primary_dark);
        }
    });

    tabs.setViewPager(pager);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_mercadoria_form, menu);
    return true;
}
}

我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include
    android:id="@+id/toolbarMercadoria"
    layout="@layout/toolbar_default"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    />

<foxy.com.br.mobile.controller.widget.SlidingTabLayout
    android:id="@+id/tabsMercadoria"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="2dp"
    android:background="@color/primary"/>

<android.support.v4.view.ViewPager
    android:id="@+id/pagerMercadoriaForm"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</android.support.v4.view.ViewPager>

</LinearLayout>

我的适配器:

public class MercadoriaFragmentPageAdapter extends FragmentPagerAdapter {

private static final int PAGES_NUMBER = 2;

private MercadoriaFormFragment mercadoriFormFragment;
private MercadoriaAvaliacoesSensoriaisFragment avaliacoesSensoriaisFragment;

public MercadoriaFragmentPageAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int position) {
    if (position == 0) {
        return getMercadoriFormFragment();
    }
    if (position == 1) {
        return getAvaliacoesSensoriaisFragment();
    }
    return null;
}

@Override
public int getCount() {
    return PAGES_NUMBER;
}

@Override
public CharSequence getPageTitle(int position) {
    if (position == 0) {
        return "Dados";
    }
    if (position == 1) {
        return "A. Sensoriais";
    }
    return null;
}

public MercadoriaAvaliacoesSensoriaisFragment getAvaliacoesSensoriaisFragment() {
    if (avaliacoesSensoriaisFragment == null)
        avaliacoesSensoriaisFragment = new MercadoriaAvaliacoesSensoriaisFragment();
    return avaliacoesSensoriaisFragment;
}

public MercadoriaFormFragment getMercadoriFormFragment() {
    if (mercadoriFormFragment == null)
        mercadoriFormFragment = mercadoriFormFragment.newInstance();
    return mercadoriFormFragment;
}
}

但我的标签不会显示。我不知道我错过了什么,所以我最终得到了这个屏幕:

enter image description here

我真的可以使用一些帮助:B,如果我能提供任何额外的信息,请告诉我。

3 个答案:

答案 0 :(得分:1)

你没有正确使用Butterknife。在onCreate()方法中,添加@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_form_mercadoria); // Add the following ButterKnife.inject(this); setSupportActionBar(toolbar); adapter = new MercadoriaFragmentPageAdapter(getSupportFragmentManager()); pager.setAdapter(adapter); tabs.setDistributeEvenly(true); tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() { @Override public int getIndicatorColor(int position) { return getResources().getColor(R.color.primary_dark); } }); tabs.setViewPager(pager); }

schema: {
    data: "ranks"
},

答案 1 :(得分:0)

你试过尺码玩吗?匹配父项从父项获取所有维度,似乎从屏幕中取出。尝试使用“Xdp”,其中X放置一个数值并检查出来。

答案 2 :(得分:0)

我发现了我的问题,在我的问题中没有清楚,因为我没有发布AbstractActivity类,我已经调用了setContent方法,所以问题是我调用了setContent两次.. 谢谢你的帮助。