我在developer.android.com上學習文檔,在課程「樣式操作欄」,我遇到了問題。我需要更改背景的ActionBar,作爲here。我使用Android Action Bar Style Generator生成了所有圖像(用於背景,按鈕等),並將結果添加到我的項目的res/dir中。
它看起來像這樣: 無法自定義ActionBar
我手動添加文件RES /價值/的themes.xml,因爲它沒有創建項目後存在。 這裏是RES /值的代碼/的themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<!--<item name="android:actionBarStyle">@style/MyActionBar</item>-->
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/ab_solid_example</item>
<!-- Support library compatibility -->
<item name="background">@drawable/ab_solid_example</item>
</style>
</resources>
,並應用這一主題,我加
用於應用程序的機器人:主題= 「@風格/ CustomActionBarTheme」
以及AndroidManifest.xml中的2個活動。這裏是AndroidManifest.xml中的代碼:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme" >
<activity
android:name="com.example.mysecondapp.app.MainActivity"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.mysecondapp.app.DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName="com.example.mysecondapp.app.MainActivity"
android:theme="@style/CustomActionBarTheme">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.mysecondapp.app.MainActivity" />
</activity>
</application>
但是,結果沒有背景的變化。 前瞻:
如果我上運行模擬器這個程序,什麼也沒有發生過。
有誰知道如何解決它?
感謝您對此事發表評論,但正如我說,我學習,我想了解從offcial機器人爲什麼我的榜樣文檔不起作用,因爲我完成了所有工作,因爲它是用文檔編寫的。 – Alexander 2014-09-19 11:41:29