简体   繁体   English

更改android操作栏的背景颜色,基础教程

[英]Change background color of an android actionbar, base tutorial

I'm trying to change the ActionBar color of a New Android Application made by Eclipse wizard following the android tutorial ( here ), but i got several problems. 我试图在Android教程( 这里 )之后改变由Eclipse向导制作新Android应用程序的ActionBar颜色,但是我遇到了一些问题。

I set minSdkVersion to 10 (it should be android 2.1 or so). 我将minSdkVersion设置为10(它应该是android 2.1左右)。

When i paste this code into themes.xml (as said by the tutorial): 当我将此代码粘贴到themes.xml时(如教程所述):

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

        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
           parent="@style/AppTheme">
        <item name="android:background">#FFFFFF</item>

        <!-- Support library compatibility -->
        <item name="background">#FFFFFF</item>
    </style>
</resources>

Eclipse give to me those errors: Eclipse给我这些错误:

  • line 5: android:actionBarStyle requires API level 11 (current min is 10) 第5行:android:actionBarStyle需要API级别11(当前最小值为10)
  • line 8: error: Error: No resource found that matches the given name: attr 'actionBarStyle'. 第8行:错误:错误:找不到与给定名称匹配的资源:attr'actionBarStyle'。
  • line 16: error: Error: No resource found that matches the given name: attr 'background'. 第16行:错误:错误:找不到与给定名称匹配的资源:attr'background'。

I modded little things (Base theme and Color), however the clean code is in the tutorial. 我修改了一些小东西(基本主题和颜色),但是干净的代码在教程中。

My Styles.xml is here: 我的Styles.xml在这里:

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

What's the problem? 有什么问题?

To use action bar below api level 11 you need to reference app compact (from the support library) in your project. 要使用api level 11下面的操作栏,您需要在项目中引用app compact(来自支持库)。

Your class needs to extends ActionBarActivity and you need to use Theme.AppCompat . 您的类需要扩展ActionBarActivity ,您需要使用Theme.AppCompat

http://developer.android.com/guide/topics/ui/actionbar.html http://developer.android.com/guide/topics/ui/actionbar.html

Also check this 还检查一下

http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html

Or you need to use ActionBarSherlock 或者您需要使用ActionBarSherlock

http://actionbarsherlock.com/ http://actionbarsherlock.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM