这个活动已经有靠窗户的装饰提供一个操作栏(FEATURE_ACTION_BAR) [英] This Activity already has an action bar supplied by the window decor (FEATURE_ACTION_BAR)
问题描述
这个活动已经有靠窗户的装饰提供一个操作栏。不要求Window.FEATURE_ACTION_BAR并设置windowActionBar为false,你的主题使用工具栏,而不是的
这是我得到的错误,我搜索的解决方案,但我没有找到如何解决这个问题。 这是我的code:
styles.xml
<! - 基本应用主题。 - >
<样式名称=AppTheme父=Theme.AppCompat.Light.DarkActionBar>
<项目名称=colorPrimary> @色/ myPrimaryColor< /项目>
<项目名称=colorPrimaryDark> @色/ myPrimaryDarkColor< /项目>
<项目名称=colorAccent> @色/ myAccentColor< /项目>
<项目名称=机器人:textColorPrimary> @色/ myTextPrimaryColor< /项目>
< /风格>
<样式名称=ActionBarPopupThemeOverlay父=Theme.AppCompat.Light.NoActionBar>
<项目名称=windowActionBar>假< /项目>
< /风格>
<样式名称=Toolbartitle父=@风格/ TextAppearance.Widget.AppCompat.Toolbar.Title>
<项目名称=机器人:文字颜色> @android:彩色/白< /项目>
< /风格>
<样式名称=ToolbarSubtitle父=@风格/ TextAppearance.Widget.AppCompat.Toolbar.Subtitle>
<项目名称=机器人:文字颜色>#56FFFFFF< /项目>
< /风格>
send_comment.xml (我的活动布局)
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
< android.support.v7.widget.Toolbar
的xmlns:程序=http://schemas.android.com/apk/res-auto
机器人:ID =@ + ID / my_toolbar
机器人:layout_height =128dp
应用程序:popupTheme =@风格/ ActionBarPopupThemeOverlay
机器人:layout_width =match_parent
机器人:ATTR / colorPrimary后台=
机器人:以下属性来=72dp
机器人:paddingBottom会=16DP
机器人:重力=底
应用程序:titleTextAppearance =@风格/ Toolbartitle
应用程序:subtitleTextAppearance =@风格/ ToolbarSubtitle
应用程序:主题=@风格/ ThemeOverlay.AppCompat.Light
机器人:标题=תגובה
/>
< / RelativeLayout的>
SendComment.java
公共类SendComment扩展ActionBarActivity {
私人工具条工具栏;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.send_comment);
工具栏=(栏)findViewById(R.id.my_toolbar);
toolbar.setTitle();
setSupportActionBar(工具栏);
}
}
我是什么做错了吗?
在你AppTheme风格的使用,
Theme.AppCompat.Light.NoActionBar
而不是
Theme.AppCompat.Light.DarkActionBar
您要设置一个主题,有一个动作条,然后要设置工具栏为动作条。这就是为什么你收到此错误。
使用,有没有动作条,而不是主题,它会解决这个问题。
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
This is the error I got, I searched for solutions but I didn't find how to solve it. This is my code:
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/myPrimaryColor</item>
<item name="colorPrimaryDark">@color/myPrimaryDarkColor</item>
<item name="colorAccent">@color/myAccentColor</item>
<item name="android:textColorPrimary">@color/myTextPrimaryColor</item>
</style>
<style name="ActionBarPopupThemeOverlay" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
</style>
<style name="Toolbartitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="ToolbarSubtitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle">
<item name="android:textColor">#56FFFFFF</item>
</style>
send_comment.xml(my activity layout)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_toolbar"
android:layout_height="128dp"
app:popupTheme="@style/ActionBarPopupThemeOverlay"
android:layout_width="match_parent"
android:background="?attr/colorPrimary"
android:paddingLeft="72dp"
android:paddingBottom="16dp"
android:gravity="bottom"
app:titleTextAppearance="@style/Toolbartitle"
app:subtitleTextAppearance="@style/ToolbarSubtitle"
app:theme="@style/ThemeOverlay.AppCompat.Light"
android:title="תגובה"
/>
</RelativeLayout>
SendComment.java
public class SendComment extends ActionBarActivity {
private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.send_comment);
toolbar = (Toolbar) findViewById(R.id.my_toolbar);
toolbar.setTitle("");
setSupportActionBar(toolbar);
}
}
What am I doing wrong?
In your AppTheme style use,
Theme.AppCompat.Light.NoActionBar
instead of
Theme.AppCompat.Light.DarkActionBar
You are setting a theme that has an actionbar and then you are setting toolbar as an actionbar. That's why your are getting this error.
Use the theme that has no actionbar instead and it will fix the issue.
这篇关于这个活动已经有靠窗户的装饰提供一个操作栏(FEATURE_ACTION_BAR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!