2017-04-26 16 views
0

私は、アプリケーションのアクションバーをツールバーに移動しようとしています。実行時に私のコードのsetSupportActionBar(toolbar)行に次のエラーが表示されます。java.lang.IllegalStateExceptionアクションバーをアンドロイドのツールバーに移動中

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

私は同じ問題について多くの投稿を行っていますが、何も動作していないようです。以下は私のコードの詳細です。

これは、関数を作成

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 
    setContentView(R.layout.activity_layout); 
    toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
} 

レイアウトファイル

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <include 
     android:id="@+id/toolbar" 
     layout="@layout/toolbar"/> 

    <FrameLayout 
     android:id="@+id/detail" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</LinearLayout> 

toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:background="@color/primary" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark"/> 

のstyles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="colorPrimary">@color/primary</item> 
     <item name="colorPrimaryDark">@color/primaryDark</item> 
     <item name="colorAccent">@color/accent</item> 
</style> 
<style name="AppMainTheme" parent="Theme.AppCompat.Light.NoActionBar" /> 
<style name="UItheme" parent="AppTheme"/> 
0123の私の活動です

マニフェストファイルには、誰かが私を可能問題は何ができるかを知らせることができ、この

<application 
     android:theme="@style/AppMainTheme"> 
     <activity 
      android:name="com.android.ui.activities.MainActivity" 
      android:launchMode="singleTask" 
      android:label="@string/app_name" 
      android:theme="@style/UItheme" > 
     </activity> 
</application> 

のようなものでしょうか?

+0

を次のスニペットを定義します。ウィンドウ機能 – Selvin

+0

@Selvinはい私はAppCompatアクティビティを使用しています。適切なサポート方法はどういう意味ですか? – Minions

+0

文書を確認してください – Selvin

答えて

0

あなたは手順

  • がAppCompatActivityであなたの活動を拡張し、次の試みることができます。
  • コメントアウトラインrequestWindowFeature
  • マニフェストファイルであなたのアクティビティのテーマを宣言します。

    <activity 
        android:name=".MainActivity" 
        android:label="@string/app_name" 
        android:theme="@style/AppTheme.NoActionBar"> 
    </activity> 
    
  • あなたは、適切な使用...要求するための支援方法を `AppCompatActivity`を(それは質問から明らかではありません)を使用している場合は、あなたのstyles.xmlに
    <style name="AppTheme.NoActionBar"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> </style>

関連する問題