微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 在Build Your First App教程中,什么是“actionbar_background”,我该如何定义它?

我正在通过Android构建您的第一个应用程序教程,我已经到了Styling The Action Bar.

我根据教程创建了这个themes.xml文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@android:style/Widget.Holo.Light.ActionBar.solid.Inverse">
    <item name="android:background">@drawable/actionbar_background</item>
</style>

我的问题是,我不知道如何定义actionbar_background.
当然,我收到以下错误

Error:(12, 41) No resource found that matches the given name (at
‘android:background’ with value ‘@drawable/actionbar_background’).

我猜这是一种颜色,但我该如何定义呢?

解决方法:

就像快速“第一次构建”的东西一样,你可以改成颜色代码,如下所示:

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@android:style/Widget.Holo.Light.ActionBar.solid.Inverse">
    <item name="android:background">#aaaaaa</item>
</style>

但是你可以把它变成任何颜色或可绘制的.

颜色通常在单独的文件中定义,如下所示:

colors.xml

<?xml version='1.0' encoding='UTF-8'?>
<resources>
    <color name="disabled_text">#9FFF</color>
    <color name="actionbar">#000</color>
    <color name="background">#111</color>
 ... etc

</resources>

和drawables定义为放置在drawables -…文件夹中的.png文件,或定义为drawables文件夹中的XML文件.

然后在这样的样式上引用:

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@android:style/Widget.Holo.Light.ActionBar.solid.Inverse">
    <item name="android:background">@color/disabled_text</item>
</style>

或者对于drawables -…文件夹中的actionbar_background.png

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@android:style/Widget.Holo.Light.ActionBar.solid.Inverse">
    <item name="android:background">@drawable/actionbar_background</item>
</style>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐