2015-10-21 39 views
0

按照這裏的教程:http://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html#試圖執行材料設計滑動標籤我做了一切按照指示。爲什麼android堅持我已經有動作欄了?

然而,當我運行程序的時候,給我的以下信息:

java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead. 

我試圖解決這一點,並嘗試了很多東西,但沒有成功。

最終我來到這個SO問題stackoverflow.com/questions/29790070/upgraded-to-appcompat-v22-1-0-and-now-getting-illegalargumentexception-appcompa並採取了回答的建議。

我改變了我的styles.xml如下:

<style name="AppBaseTheme" parent="Theme.AppCompat.NoActionBar"> 
</style> 

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 

</style> 

儘管如此,它仍然給了我同樣的錯誤消息。

剛剛完成的緣故,這裏是我的活動:

public class MainActivity extends AppCompatActivity { 

    private ViewPager mViewPager; 
    private HomeTabsPagerAdapter mPageAdapter; 

    private Toolbar mToolbar; 
    private SlidingTabLayout mTabs; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

       setContentView(R.layout.activity_main); 

       setViewsClassMembers(); 

       setSupportActionBar(mToolbar); 
       mPageAdapter = new HomeTabsPagerAdapter(getSupportFragmentManager()); 

       mViewPager.setAdapter(mPageAdapter); 
       // Assiging the Sliding Tab Layout View 
       mTabs.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 
       mTabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() { 
        @Override 
        public int getIndicatorColor(int position) { 
         return getResources().getColor(R.color.tabsScrollColor); 
        } 
       }); 

       // Setting the ViewPager For the SlidingTabsLayout 
       mTabs.setViewPager(mViewPager); 

    } 


    private void setViewsClassMembers() { 
     mViewPager = (ViewPager) findViewById(R.id.pager); 
     mToolbar = (Toolbar) findViewById(R.id.tool_bar); 
     mTabs = (SlidingTabLayout) findViewById(R.id.tabs); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     switch (item.getItemId()) { 
     case R.id.action_new_request: 
      startNewRequestActivity(); 
      break; 
     } 
     return super.onOptionsItemSelected(item); 
    } 

    private void startNewRequestActivity() { 
     Intent intent = new Intent(this, NewRequestActivity.class); 
     startActivity(intent); 
    } 

} 

任何人都可以看到問題出在哪裏?爲什麼Android堅持我已經有了行動條?

+0

「在您的主題中將windowActionBar設置爲false以使用工具欄代替」您嘗試過嗎? –

+0

@TimCastelijns是的,我已經嘗試過,許多其他似乎是相關的功能。當我將windowsActionBar設置爲false時,我得到「AppCompat不支持當前主題功能」的錯誤消息。來自Android的同一個人在另一個SO問題上寫道,AppCompat現在對它所接受的功能更爲嚴格。 – dsb

回答

0

看到它:https://stackoverflow.com/a/26515159

<item name="windowActionBar">false</item> 

您styles.xml內。

+0

謝謝。我嘗試了這個和許多其他功能。當我將這一行添加到styles.xml時,我得到「AppCompat不支持當前的主題功能」。 – dsb

相關問題