gpt4 book ai didi

android - 在构建您的第一个应用程序教程中,什么是 "actionbar_background"以及如何定义它?

转载 作者:太空宇宙 更新时间:2023-11-03 11:39:39 24 4
gpt4 key购买 nike

我正在学习 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>

但是你可以把它变成任何color或者drawable

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

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文件,或者定义为XML drawables 文件夹中的文件。

然后像这样引用样式:

<!-- 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>

关于android - 在构建您的第一个应用程序教程中,什么是 "actionbar_background"以及如何定义它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25448051/

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