ani*_*ine 13 android android-ui android-support-library material-design android-5.0-lollipop
我正在为Android 5.0准备我的应用程序,我正在使用最新的兼容性库,这是我的样式.
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/theme_accent</item>
<item name="colorAccent">@color/theme_accent_secondary</item>
</style>
<style name="AppThemeDark" parent="Theme.AppCompat">
<item name="colorPrimary">@color/theme_accent</item>
<item name="colorAccent">@color/theme_accent_secondary</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
(正在以编程方式设置ActionBar颜色.)
现在,我希望溢出/弹出菜单具有类似于holo实现中的深色背景,但我无法使其工作,这是它的样子: 
我试过设置popupMenuStyle但它没有用.
如何让弹出菜单变暗?
Der*_*Jan 20
停止使用ActionBar.如果你想要ToolBar像a 一样设置ActionBar,请在android-developers博客上关注本指南.
它实际上在Dark Action Bar中提到了你的用例,并提供了以下代码:
<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" />
Run Code Online (Sandbox Code Playgroud)
Mac*_*rse 10
不是一个完整的答案,但到目前为止我发现了:
在以前的版本中,您需要指定一个drawable(检查https://github.com/StylingAndroid/StylingActionBar代码和教程)
显然,现在这是一种颜色.要修改它,您需要指定以下主题:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:actionBarPopupTheme">@style/popupNew</item>
</style>
<style name="popupNew" parent="android:ThemeOverlay.Material.Light">
<item name="android:colorBackground">@color/red</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
如果应用于应用程序的主题就是这个,这可以正常工作.如果我添加android:actionBarPopupTheme到我现有的主题,它不起作用.我想弄明白为什么.
通过使用此样式解决了我的问题:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/theme_accent</item>
<item name="colorAccent">@color/theme_accent_secondary</item>
<item name="actionBarStyle">@style/AbStyle</item>
<item name="actionModeBackground">@color/actionmode_bg</item>
</style>
<style name="AbStyle" parent="Widget.AppCompat.Toolbar">
<item name="elevation">2dp</item>
<item name="displayOptions">homeAsUp|showTitle</item>
<!--showHome-->
</style>
<style name="AppThemeDark" parent="Theme.AppCompat">
<item name="colorAccent">@color/theme_accent_secondary</item>
<item name="actionBarStyle">@style/AbStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我不得不使用Widget.AppCompat.Toolbar作为父actionBarStyle
将属性popupTheme添加到工具栏:
<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/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_primary"
app:theme="@style/Theme.AppCompat.Light"
app:popupTheme="@style/Theme.AppCompat" />
Run Code Online (Sandbox Code Playgroud)
或者为工具栏定义新样式:
<style name="MyToolBarStyle" parent="Widget.AppCompat.Toolbar">
<item name="android:background">@color/green</item>
<item name="popupTheme">@style/Theme.AppCompat.Light</item>
<item name="theme">@style/Theme.AppCompat</item>
</style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26599 次 |
| 最近记录: |