我使用此基于Web的工具生成了 Action 栏样式,该样式非常常见
http://jgilfelt.github.io/android-actionbarstylegenerator/
我在工作区中将“android-support-v7-appcompat”作为一个单独的项目。我转储了通过从该工具下载zip文件到此项目而生成的res文件夹的所有内容。
我在操作栏和上下文菜单(弹出窗口)中使用了深蓝色的颜色。
但是,我无法从该主题获得自定义外观。大多数元素/组件显示默认外观。
操作栏为黑色(而不是蓝色),弹出菜单为灰色(而不是浅蓝色)
我的value.xml文件夹中的style.xml
<style name="Theme.dinemobileandro" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarItemBackground">@drawable/selectable_background_dinemobileandro</item>
<item name="popupMenuStyle">@style/PopupMenu.dinemobileandro</item>
<item name="dropDownListViewStyle">@style/DropDownListView.dinemobileandro</item>
<item name="actionBarTabStyle">@style/ActionBarTabStyle.dinemobileandro</item>
<item name="actionDropDownStyle">@style/DropDownNav.dinemobileandro</item>
<item name="actionBarStyle">@style/ActionBar.Solid.dinemobileandro</item>
<item name="actionModeBackground">@drawable/cab_background_top_dinemobileandro</item>
<item name="actionModeSplitBackground">@drawable/cab_background_bottom_dinemobileandro</item>
<item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.dinemobileandro</item>
<!-- Light.DarkActionBar specific -->
<item name="actionBarWidgetTheme">@style/Theme.dinemobileandro.Widget</item>
</style>
我也在 list 文件中进行了必要的更改
<application
android:name="com.railyatri.in.mobile.MainApplication"
android:allowBackup="true"
android:allowClearUserData="true"
android:enabled="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.dinemobileandro" >
我已严格按照此博客中提到的步骤进行操作,以前它对我来说适用于夏洛克主题。
http://java.dzone.com/articles/creating-custom-android-styles
但是,这次,我迁移到了appcompat,它停止了工作。我已经在SO和Google上进行了大量搜索,并尝试了一些建议但无济于事的方法。
请帮忙。提前致谢。
最佳答案
在AppCompat v21中,不推荐使用actionbarstylegenerator。
您可以使用类似这样的东西来自定义ActionBar(或者更好的Toolbar)。
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Set AppCompat's color theming attrs -->
<item name="colorPrimary">@color/my_color</item>
<item name="colorPrimaryDark">@color/my_darkercolor</item>
</style>
您可以在官方博客中找到更多信息:http://android-developers.blogspot.it/2014/10/appcompat-v21-material-design-for-pre.html
关于Android appcompat主题始终显示黑色操作栏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28629635/