gpt4 book ai didi

android - 如何更改 ActionBar 菜单背景颜色(安卓 4 和 5)

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:30:56 26 4
gpt4 key购买 nike

我在更改 android 设计时遇到了一个麻烦。我需要将操作栏菜单背景颜色更改为黑色。我知道,这个问题有很多答案。我试过很多。但对我没有任何作用。

哦,我忘了说,我不是一个非常熟练的 android 开发人员。这是我的样式文件 (v21)

<?xml version="1.0" encoding="utf-8"?>

<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
<item name="colorPrimary">@color/mainColor</item>
<item name="colorPrimaryDark">@color/secondaryColor</item>
<item name="colorAccent">@color/goldColor</item>
<item name="colorControlNormal">@color/mainColor</item>
<item name="colorControlActivated">@color/secondaryColor</item>
<item name="colorControlHighlight">@color/secondaryColor</item>
<item name="android:navigationBarColor">@color/blackColor</item>
<item name="colorSwitchThumbNormal">@color/secondaryTextColor</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:textColorPrimary">@color/goldColor</item>
<item name="android:windowBackground">@color/blackColor</item>
<item name="android:itemTextAppearance">@color/normalTextColor</item>
<item name="android:buttonStyle">@style/ButtonStyle</item>
<item name="android:actionMenuTextColor">@color/blackColor</item>
<item name="actionMenuTextColor">@color/blackColor</item>
<item name="android:actionBarPopupTheme">@style/Theme.Red.Widget</item>
<item name="android:popupTheme">@color/blackColor</item>
</style>


<style name="Theme.Red.Widget" parent="@style/Theme.AppCompat">
<item name="popupMenuStyle">@style/PopupMenu.Red</item>
<item name="dropDownListViewStyle">@style/DropDownListView.Red</item>
</style>

<style name="PopupMenu.Red" parent="@style/Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">@color/blackColor</item>
</style>

<style name="DropDownListView.Red" parent="@style/Widget.AppCompat.ListView.DropDown">
<item name="android:listSelector">@color/blackColor</item>
</style>

<color name="mainColor">#373737</color>
<color name="secondaryColor">#252525</color>
<color name="goldColor">#cea939</color>
<style name="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">?android:attr/listDivider</item>
</style>
<style name="ButtonStyle" parent="android:Widget.Button">
<item name="android:background">@drawable/custom_btn</item>
</style>

这是我为较低版本的 android 编写的代码。

<resources>

<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
<item name="colorPrimary">@color/mainColor</item>
<item name="colorPrimaryDark">#856f2d</item>
<item name="colorAccent">@color/mainColor</item>
<item name="colorControlNormal">@color/mainColor</item>
<item name="colorControlActivated">#856f2d</item>
<item name="colorControlHighlight">#856f2d</item>
<item name="colorSwitchThumbNormal">@color/mainColor</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:textColorPrimary">@color/blackColor</item>
<item name="android:textColorSecondary">@color/blackColor</item>
<item name="android:textColorTertiary">@color/blackColor</item>
<item name="android:windowBackground">@color/backgroundColor</item>
<item name="android:itemTextAppearance">@color/normalTextColor</item>

<item name="android:editTextBackground">@drawable/apptheme_edit_text_holo_light</item>
<item name="android:textColorHighlight">#99cea939</item>
<item name="android:textSelectHandleLeft">@drawable/apptheme_text_select_handle_left</item>
<item name="android:textSelectHandleRight">@drawable/apptheme_text_select_handle_right</item>
<item name="android:textSelectHandle">@drawable/apptheme_text_select_handle_middle</item>
<item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewAppTheme</item>
<item name="android:listChoiceIndicatorMultiple">@drawable/apptheme_btn_check_holo_light</item>
<item name="android:listChoiceIndicatorSingle">@drawable/apptheme_btn_radio_holo_light</item>
<item name="android:buttonStyle">@style/ButtonAppTheme</item>
<item name="android:imageButtonStyle">@style/ImageButtonAppTheme</item>
<item name="android:dropDownSpinnerStyle">@style/SpinnerAppTheme</item>
<item name="android:progressBarStyleHorizontal">@style/ProgressBarAppTheme</item>
<item name="android:seekBarStyle">@style/SeekBarAppTheme</item>
<item name="android:ratingBarStyle">@style/RatingBarAppTheme</item>
<item name="android:ratingBarStyleIndicator">@style/RatingBarBigAppTheme</item>
<item name="android:ratingBarStyleSmall">@style/RatingBarSmallAppTheme</item>
<item name="android:buttonStyleToggle">@style/ToggleAppTheme</item>
<item name="android:listChoiceBackgroundIndicator">@drawable/apptheme_list_selector_holo_light</item>
<item name="android:activatedBackgroundIndicator">@drawable/apptheme_activated_background_holo_light</item>
<item name="android:fastScrollThumbDrawable">@drawable/apptheme_fastscroll_thumb_holo</item>

</style>

<style name="SettingsToolbarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">@color/goldColor</item>
<item name="actionMenuTextColor">@color/abc_primary_text_material_light</item>
<item name="android:textColorSecondary">@color/goldColor</item>
</style>

<style name="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">?android:attr/listDivider</item>
</style>
<style name="AutoCompleteTextViewAppTheme" parent="android:Widget.Holo.Light.AutoCompleteTextView">
<item name="android:dropDownSelector">@drawable/apptheme_list_selector_holo_light</item>
<item name="android:background">@drawable/apptheme_edit_text_holo_light</item>
</style>
<style name="ButtonAppTheme" parent="android:Widget.Holo.Light.Button">
<item name="android:background">@drawable/apptheme_btn_default_holo_light</item>
</style>
<style name="ImageButtonAppTheme" parent="android:Widget.Holo.Light.ImageButton">
<item name="android:background">@drawable/apptheme_btn_default_holo_light</item>
</style>
<style name="SpinnerAppTheme" parent="android:Widget.Holo.Light.Spinner">
<item name="android:background">@drawable/apptheme_spinner_background_holo_light</item>
<item name="android:dropDownSelector">@drawable/apptheme_list_selector_holo_light</item>
</style>
<style name="TabAppTheme">
<item name="android:gravity">center_horizontal</item>
<item name="android:paddingLeft">16dip</item>
<item name="android:paddingRight">16dip</item>
<item name="android:background">@drawable/apptheme_tab_indicator_holo</item>
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">1</item>
<item name="android:minWidth">80dip</item>
</style>
<style name="TabTextAppTheme">
<item name="android:textColor">#000000</item>
<item name="android:textSize">12sp</item>
<item name="android:textStyle">bold</item>
<!-- v14 <item name="android:textAllCaps">true</item> -->
<item name="android:ellipsize">marquee</item>
<item name="android:maxLines">2</item>
<item name="android:maxWidth">180dip</item>
</style>
<style name="ProgressBarAppTheme" parent="android:Widget.Holo.Light.ProgressBar.Horizontal">
<item name="android:progressDrawable">@drawable/apptheme_progress_horizontal_holo_light</item>
<item name="android:indeterminateDrawable">@drawable/apptheme_progress_indeterminate_horizontal_holo_light</item>
</style>
<style name="SeekBarAppTheme" parent="android:Widget.Holo.Light.SeekBar">
<item name="android:progressDrawable">@drawable/apptheme_scrubber_progress_horizontal_holo_light</item>
<item name="android:indeterminateDrawable">@drawable/apptheme_scrubber_progress_horizontal_holo_light</item>
<item name="android:thumb">@drawable/apptheme_scrubber_control_selector_holo_light</item>
</style>
<style name="RatingBarAppTheme" parent="android:Widget.Holo.Light.RatingBar">
<item name="android:progressDrawable">@drawable/apptheme_ratingbar_full_holo_light</item>
<item name="android:indeterminateDrawable">@drawable/apptheme_ratingbar_full_holo_light</item>
</style>
<style name="RatingBarBigAppTheme" parent="android:Widget.Holo.Light.RatingBar.Indicator">
<item name="android:progressDrawable">@drawable/apptheme_ratingbar_holo_light</item>
<item name="android:indeterminateDrawable">@drawable/apptheme_ratingbar_holo_light</item>
</style>
<style name="RatingBarSmallAppTheme" parent="android:Widget.Holo.Light.RatingBar.Small">
<item name="android:progressDrawable">@drawable/apptheme_ratingbar_small_holo_light</item>
<item name="android:indeterminateDrawable">@drawable/apptheme_ratingbar_small_holo_light</item>
</style>
<style name="ToggleAppTheme" parent="android:Widget.Holo.Light.Button.Toggle">
<item name="android:background">@drawable/apptheme_btn_toggle_holo_light</item>
</style>

如果您能提供帮助,我将不胜感激。

最佳答案

将 actionOverflowMenuStyle 项添加到您的应用主题

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionOverflowMenuStyle">@style/CMOptionsMenu</item>
</style>


<style name="CMOptionsMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<item name="android:popupBackground">your color code</item>
</style>

关于android - 如何更改 ActionBar 菜单背景颜色(安卓 4 和 5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28974855/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com