实现自定义主题的Android问题

mis*_*ded 4 android themes

我的android项目

AndoidManifest.xml 具有

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfirstapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:debuggable="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomActionBarTheme" >
        <activity
            android:name="com.example.myfirstapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:name="com.example.myfirstapp.DisplayMessageActivity"
            android:label="@string/title_activity_display_message"
            android:parentActivityName="com.example.myfirstapp.MainActivity" >
         <meta-data 
             android:name="android.support.PARENT_ACTIVITY"
             android:value="com.example.myfirstapp.MainActivity" /> 
        </activity>
    </application>


</manifest>
Run Code Online (Sandbox Code Playgroud)

当我尝试在下面实现自定义主题时 res\values\themes.xml

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

       <style name="MyActionBar"            
           parent="@style/Widget.Holo.Light.ActionBar.Solid.Inverse">
       <item name="android:background">@drawable/actionbar_background</item>
       </style>  
</resources>
Run Code Online (Sandbox Code Playgroud)

我得到错误指定

Error retrieving parent for item: No resource found that matches the given name '@style/Theme.Holo.Light.DarkActionBar'.Error retrieving parent for item: No resource found that matches the given name '@style/ Widget.Holo.Light.ActionBar.Solid.Inverse'.

Yui*_*aki 6

你必须android:在风格之前写,即@android:style/Theme.Holo.Light.DarkActionBar.

  • 检查你的res/drawable或res/drawable-something目录.有actionbar_background.png还是actionbar_background.xml? (3认同)
  • 也许你暂时可以暂时使用一种简单的颜色.喜欢<item name ="android:background">#ffccff </ item>.您可以稍后添加自己的图像背景. (2认同)