0

按照这里的教程:http ://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html#尝试执行材料设计滑动标签我按照指示做了一切。

但是,当我运行该应用程序时,它给了我以下消息:

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坚持我已经有动作栏?

4

1 回答 1

0

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

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

在您的styles.xml 中。

于 2015-10-21T08:57:32.290 回答