此活动已经有一个由窗口装饰提供的操作栏。不要求Window.FEATURE_SUPPORT_ACTION_BAR

时间:2015-10-09 19:04:48

标签: android

我收到了这个错误

  

此活动已有窗口装饰提供的操作栏。请勿请求Window.FEATURE_SUPPORT_ACTION_BAR并进行设置   在您的主题中,windowActionBar为false,而不是使用工具栏

我看到了这个SO Question  他们说了

think you're developing for Android L but anyway Include this line

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

inside your styles.xml.

当我申请时,我遇到了这个错误

AppCompat does not support the current theme features: { windowActionBar: false, windowActionBarO

这是我的代码

public class MainActivity extends AppCompatActivity {

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

        Toolbar toolbar = (Toolbar) findViewById(R.id.drawer_layout);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);    }

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

    private void initToolbars() {



        Toolbar toolbarBottom = (Toolbar) findViewById(R.id.drawer_layout);
        toolbarBottom.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch(item.getItemId()){
                    case R.id.action_settings:
                        // TODO
                        break;
                    // TODO: Other cases
                }
                return true;
            }
        });
        toolbarBottom.inflateMenu(R.menu.menu_main);

    }
    @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.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

1 个答案:

答案 0 :(得分:2)

您必须从NoActionBar样式继承您的样式:

<style name="Base.Theme.MyApp" parent="Theme.AppCompat.NoActionBar">

然后在AppBarLayout中使用主题叠加层:

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">