为什么Android的坚持,我已经行动起来吧?来吧、我已经、行动、Android

由网友(这就是人生。)分享简介:继教程此处的http://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html#试图执行材料设计滑动片我所做的一切的指示。Following the tutorial here: http://www.android4de...

继教程此处的http://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html#试图执行材料设计滑动片我所做的一切的指示。

Following the tutorial here: http://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html# trying to perform material design sliding tabs I did everything as instructed.

然而,当我运行应用程序,它给了我下面的消息:

However, when I run the app it gave me the following message:

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.

我试图解决这一点,并尝试了许多事情,但没有成功。

I tried to resolve this and tried many thing, with no success.

最后,我来到这太问题stackoverflow.com/questions/29790070/upgraded-to-appcompat-v22-1-0-and-now-getting-illegalargumentexception-appcompa并采取了回答建议。

Eventually I came to this SO question stackoverflow.com/questions/29790070/upgraded-to-appcompat-v22-1-0-and-now-getting-illegalargumentexception-appcompa and took the answered suggestion.

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

I changed my styles.xml as follows:

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

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

</style>

尽管如此,它仍然给了我同样的错误消息。

Nevertheless, it still gives me the same error message.

只是为了完成,这是我的活动:

Just for the sake of completion, here is my Activity:

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的坚持,我已经有行动起来吧?

Can anyone see where is the problem? why do Android insists that I am already having action bar?

推荐答案

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

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

您styles.xml中。

inside your styles.xml.

阅读全文

相关推荐

最新文章