2 fruit fruit fruit_fruit 于 2017.09.20 09:20 提问

TabLayout一调用方法就软件闪退

<?xml version="1.0" encoding="utf-8"?>
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="wz.com.mytablayout.MainActivity">

<android.support.design.widget.TabLayout
    android:id="@+id/tab"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:background="@color/colorAccent"
    />

package wz.com.mytablayout;

import android.support.design.widget.TabLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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


    tabLayout=(TabLayout)findViewById(R.id.tab);
    tabLayout.addTab(tabLayout.newTab().setText("Tab1"));
    tabLayout.addTab(tabLayout.newTab().setText("Tab2"));
    tabLayout.addTab(tabLayout.newTab().setText("Tab3"));

}

}

1个回答

ziyejinwei1994
ziyejinwei1994   2017.09.20 09:55

把你的报错信息拿出来,看看是哪里出的错

ziyejinwei1994
ziyejinwei1994 回复fruit_fruit: 嗯 如果可以采纳下吧 虽然没帮到忙
2 个月之前 回复
fruit_fruit
fruit_fruit 谢谢,已解决,是我添加的design依赖包与support版本不一致
2 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片