背景
我正在努力为应用程序添加一些材料设计风格,因此我为操作栏和状态栏选择了不同的颜色。
问题
为此,应用程序的主题是“Theme.AppCompat.Light.DarkActionBar”,并添加此主题以隐藏操作栏,因为我需要将其作为工具栏处理:
我用过的主题:
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionModeOverlay">true</item>
</style>
我使用过的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/activity_app_list__toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
tools:ignore="UnusedAttribute"/>
</LinearLayout>
code:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_toolbar=(Toolbar)findViewById(R.id.activity_app_list__toolbar);
setSupportActionBar(_toolbar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menu_main,menu);
return super.onCreateOptionsMenu(menu);
}
由于某种原因,我得到了这种行为:
- 操作项和溢出项的子菜单是黑色的。
- 当点击搜索操作项时,溢出项是白色的。
我想自定义这些弹出菜单,以便它们保持一致。
我尝试过的
我尝试过使用这个:
<item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
...
<style name="OverflowMenu" parent="Widget.AppCompat.Light.PopupMenu.Overflow">
</style>
但这根本没有帮助。
问题
有谁知道如何处理这个问题?这是支持库中的错误吗?
对我来说它看起来是这样的,所以我已经报告了它here https://code.google.com/p/android/issues/detail?id=172448,包括一个示例项目。
您可以使用以下命令自定义溢出菜单popupTheme
属性:
<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="@dimen/triple_height_toolbar"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
原来的答案遗漏了一些要点:
首先,工具栏应该有:
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"/>
对于轻量弹出窗口,请使用以下命令:
<style name="AppTheme.Light" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarTheme">@style/AppTheme.ActionBarTheme.Light</item>
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
</style>
<style name="AppTheme.ActionBarTheme.Light" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlActivated">#FFffffff</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
</style>
对于深色弹出窗口,请使用以下命令:
<style name="AppTheme.Light" parent="@style/Theme.AppCompat.NoActionBar">
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
<item name="actionBarTheme">@style/AppTheme.ActionBarTheme.Dark</item>
</style>
<style name="AppTheme.ActionBarTheme.Dark" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlActivated">#FFffffff</item>
<item name="android:textColorPrimary">#FFffffff</item>
</style>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)