在 Android Studio 中制作滑动标签时出错

Error in making of Swipe Tabs in Android Studio

// I was making swipe Tabs in android Studio i got a error 
// i cannot paste all the code please follow this link to see more information
https://www.youtube.com/watch?v=VVahIc8yENk

我还提到了我哪里出错了,是什么错误,请阅读这篇文章

package com.example.rahul.swipetabs;    

import android.support.v4.app.FragmentActivity;    
import android.os.Bundle;    
import android.app.ActionBar;

public class MainActivity extends FragmentActivity  {

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

        mActionBar = getActionBar();         

        mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
      //error #1
        mActionBar.Tab tab1 = mActionBar.newTab(); 
       //error #2 
        // i had explain all the errors below            
    }
}

mActionBar.setNavigationMode (ActionBar.NAVIGATION_MODE_TABS);

//error #1 : Here set Navigation mode & NAVIGATION_MODE_TABS  is depreciated 
// How can i solve this problem if it is depreciated 
//can i still use this if it is depreciated    

//mActionBar.Tab tab1 = mActionBar.newTab();  

//error #2 :  "Tab"  in code  says that Tab cannot resolve symbol 

是的,您可以使用已弃用的方法。

而不是这个:

      mActionBar.Tab tab1 = mActionBar.newTab(); 

添加这个

    ActionBar.Tab tab1 = mActionBar.newTab(); 
     tab1.setText("Tab 1");

在这里面,我们需要用ActionBar.Tab来调用意味着Tab是ActionBar的静态字段class所以我们需要用class名称来调用它而不是对象名称。