0

Android でタブをスライドさせるためのデモを作成しています。

必要なすべての Java および Xml ファイルを追加した後、アプリがクラッシュします。

参考にしたリンク

上記のリンクを使用して、デモを作成しました。

MainActivity.java

public class MainActivity extends AppCompatActivity {

    // Declaring Your View and Variables

    Toolbar toolbar;
    ViewPager pager;
    ViewPagerAdapter adapter;
    SlidingTabLayout tabs;
    CharSequence Titles[]={"Home","Events"};
    int Numboftabs =2;

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


        // Creating The Toolbar and setting it as the Toolbar for the activity

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


        // Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
        adapter =  new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);

        // Assigning ViewPager View and setting the adapter
        pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(adapter);

        // Assiging the Sliding Tab Layout View
        tabs = (SlidingTabLayout) findViewById(R.id.tabs);
        tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width

        // Setting Custom Color for the Scroll bar indicator of the Tab View
        tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
            @Override
            public int getIndicatorColor(int position) {
                return getResources().getColor(R.color.tabsScrollColor);
            }
        });

        // Setting the ViewPager For the SlidingTabsLayout
        tabs.setViewPager(pager);



    }

Logcat のエラー

07-08 13:49:32.710: E/AndroidRuntime(7625): FATAL EXCEPTION: main
    07-08 13:49:32.710: E/AndroidRuntime(7625): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.slidingtab/com.example.slidingtab.MainActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class com.android4devs.slidingtab.SlidingTabLayout
    07-08 13:49:32.710: E/AndroidRuntime(7625):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
    07-08 13:49:32.710: E/AndroidRuntime(7625):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
    07-08 13:49:32.710: E/AndroidRuntime(7625):     at android.app.ActivityThread.access$600(ActivityThread.java:149)
    07-08 13:49:32.710: E/AndroidRuntime(7625):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)

このエラーを解決するのを手伝ってください。

4

2 に答える 2