2013-10-27 16 views
0

我用行动吧应用自定义主题操作栏后这么想的显示

styles.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 

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

    <color name="custom_theme_color">#ffa900</color> 

    <style name="CustomTheme" parent="android:Theme.Light"> 
     <item name="android:windowBackground">@color/custom_theme_color</item> 
     <item name="android:colorBackground">@color/custom_theme_color</item> 
    </style> 

</resources> 

清单有一个应用程序

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

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

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

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

我的问题是,最初由默认它使用Theme.Light并显示操作栏,但是当我使用父母作为Theme.Light自定义了一个主题时,它不起作用,但是如果我使用父级作为Theme.Holo,那么它适用于自定义主题。任何人任何想法。

回答

0

这是我所做的。它对我来说是完美的。在水库 - >值 - >风格

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<!-- the theme applied to the application or activity --> 
<style name="CustomTheme" 
     parent="@style/Theme.Light">  

     <item android:name="actionBarStyle">@style/MyActionBar</item> 

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

然后在绘制文件夹(创建一个,如果你没有的话),创建一个新的XML actionbar_background并粘贴在它下面的代码。

<?xml version="1.0" encoding="utf-8"?> 
    <bitmap android:tileMode="repeat" 
    android:src="@drawable/ab_texture_tile_example" 
    xmlns:android="http://schemas.android.com/apk/res/android"/> 

然后,将您的自定义颜色放在其他可绘制文件夹中。这里ab_texture_title_example是我使用的背景颜色。

+1

使用下面的链接创建自定义背景颜色。 http://jgilfelt.github.io/android-actionbarstylegenerator/ – Sharan