私は、アプリケーションのアクションバーをツールバーに移動しようとしています。実行時に私のコードの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>
のようなものでしょうか?
を次のスニペットを定義します。ウィンドウ機能 – Selvin
@Selvinはい私はAppCompatアクティビティを使用しています。適切なサポート方法はどういう意味ですか? – Minions
文書を確認してください – Selvin