WIS*_*SHY 14 android menu popup toolbar android-optionsmenu
我正在使用Android工具栏.我只想更改溢出菜单的背景颜色.但它并没有改变.
风格xml
<style name="MyDarkToolbarStyle" parent="Widget.AppCompat.Toolbar">
<item name="popupTheme">@style/PopupMenuStyle</item>
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
<style name="PopupMenuStyle" parent="android:Widget.Holo.Light.PopupMenu">
<item name="android:popupBackground">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
工具栏XML
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorPrimary"
android:elevation="2dp"
android:theme="@style/MyDarkToolbarStyle" />
Run Code Online (Sandbox Code Playgroud)
Apu*_*rva 73
要更改工具栏选项菜单颜色,请将其添加到工具栏元素
app:popupTheme="@style/MyDarkToolbarStyle"
Run Code Online (Sandbox Code Playgroud)
然后在您的styles.xml定义弹出菜单样式
<style name="MyDarkToolbarStyle" parent="ThemeOverlay.AppCompat.Light">
<item name="android:colorBackground">@color/mtrl_white_100</item>
<item name="android:textColor">@color/mtrl_light_blue_900</item>
</style>
Run Code Online (Sandbox Code Playgroud)
请注意,您需要使用colorBackground 不 background.后者将应用于所有内容(菜单本身和每个菜单项),前者仅适用于弹出菜单.
coz*_*eJ4 11
编辑:
如果你只想要一个白色溢出弹出菜单就行了
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorPrimary"
android:elevation="2dp"
app:theme="@style/MyDarkToolbarStyle"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"" />
Run Code Online (Sandbox Code Playgroud)
并删除多余的popupTheme你的Style xml
<style name="MyDarkToolbarStyle" parent="Widget.AppCompat.Toolbar">
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
Run Code Online (Sandbox Code Playgroud)
您还应该在顶部(父级)布局中包含此内容
xmlns:app="http://schemas.android.com/apk/res-auto"
Run Code Online (Sandbox Code Playgroud)
最简单的方法
如果只想要白色溢出弹出菜单,请执行以下操作:
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/ColorPrimary"
android:elevation="2dp"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
Run Code Online (Sandbox Code Playgroud)
另外,看看android:layout_height属性的值。
| 归档时间: |
|
| 查看次数: |
31342 次 |
| 最近记录: |