2017-03-05 22 views
0
// 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 

我也提到在那裏我得到了一個錯誤,什麼錯誤請仔細閱讀本錯誤刷卡標籤的製作Android Studio中

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 
+0

「我還可以使用這個,如果它是貶值」 - 一段時間,是的。理想情況下,你使用別的東西。有很多方法可以在Android中創建滑動選項卡:「TabLayout」,「PagerTtrip」,第三方選項卡指示符庫等。 – CommonsWare

回答

0

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

取而代之的是:

 mActionBar.Tab tab1 = mActionBar.newTab(); 

添加此

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

在在此,我們需要調用與ActionBar.Tab意味着Tab是動作條類的靜態字段因此,我們需要用類名稱而不是對象名稱來調用它。

+0

您能否向我解釋代碼的含義以及我們爲什麼使用。Tab –

+0

@Aliaketh In in這個,我們需要用ActionBar.Tab調用方式Tab是一個ActionBar類的靜態字段。 – vicky