我正在为应用添加一些材质设计风格,所以我为动作栏和状态栏选择了不同的颜色。
为此,该应用程序的主题是“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>
代码:
@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,包括一个示例项目。
答案 0 :(得分:3)
您可以使用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>