不要求Window.FEATURE_SUPPORT_ACTION_BAR

时间:2017-01-11 08:50:10

标签: android

我有一个LoginActivityclass(TabActivity),它有以下代码来覆盖整个手机屏幕

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        FacebookSdk.sdkInitialize(getApplic

现在我想使用具有工具栏的Intent转到另一个MainActivityclass(AppCompatActivity)。它的代码是 -

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

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

XML -

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        app:contentInsetRight="@dimen/fab_margin"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

虽然我没有使用Intent打开MainClass,但是我想要打开MainActivityClass有错误 -

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

2 个答案:

答案 0 :(得分:5)

试试这个:

清单中的

'//a[normalize-space(.)="Add New Button"]'
style.xml中的

// the activity where you want to show `toolbar`
    <activity android:name=".YourActivity"  
     android:theme="@style/AppTheme.NoActionBar"><!-- ADD THIS LINE -->

将此<style name="AppTheme.NoActionBar"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> </style> 添加到清单文件

中的应用程序代码中
android:theme="@style/Theme.AppCompat.Light"

答案 1 :(得分:0)

许多错误都会导致此错误 我在下面列出了一些情况:

1。)如果您尚未在布局中创建工具栏

2.。)如果您正在使用

android:theme="@style/AppTheme.NoActionBar"

主题并尝试获取Actionbar。

3)如果你还没有

extends AppCompatActivity