【发布时间】:2014-11-21 12:54:34
【问题描述】:
我已遵循指南http://android-developers.blogspot.co.uk/2014/10/appcompat-v21-material-design-for-pre.html 并将工具栏实现为 ActionBar,但我似乎无法更改工具栏的主题。我使用 Theme.AppCompat.Light 作为我应用的基本主题,并希望单独设置样式/主题工具栏/操作栏。
向我的 app_coomon_toolbar_xml 添加样式完全没有影响 例如当我在下面添加时
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
它的 app_common_toolbar.xml 主题没有改变,它仍然是从主应用程序主题中挑选出来的,即 Theme.AppCompat.Light。
仅当我将 App 基本主题更改为 Theme.AppCompat.Light.DarkActionBar 时,工具栏主题才会更改。我不想那样做。 我做错了什么?
这里是我的工具栏的详细信息以及我如何加载它
app_common_toolbar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/ android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/app_common_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
MainActivity.java super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.app_common_toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
}
【问题讨论】:
-
如果您要调用
setSupportActionBar,那么您的主题不应该有操作栏。 -
你的意思是我不应该将主题与像 ThemeOverlay.AppCompat.Dark.ActionBar 这样的操作栏一起使用吗?
-
按您的方式尝试。您将在
setSupportActionBar上收到一条错误消息,告诉您您已经有一个操作栏。 -
不,它没有,它工作正常
-
不确定这怎么可能。在这里查看我的模板
https://github.com/kanytu/android-material-drawer-template。它使用没有操作栏的主题。