4

I'm a beginner in Android development and I trying to build my theme but I have a problem. I tried searching answers on google, d.android but to no avail.

ActionBar is changing color (this is OK), but text and icon of app doesn't show (only if I use my theme - if I use default theme everything is OK). Why?

res/values/styles.xml:

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

<style name="AppBaseTheme" parent="android:Theme.Light">
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="AppTheme">
    <item name="android:background">HEX COLOR</item>
    <item name="android:titleTextStyle">@style/MyTitleTextStyle</item>
</style>

<style name="MyTitleTextStyle" parent="AppTheme">
    <item name="android:textColor">#FFFFFF</item>
</style>

</resources>

Here is my AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.appname"
        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/AppTheme" >

        <activity
            android:name="com.example.appname.Intro"
            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>
MartinK
  • 43
  • 1
  • 4
  • I have the same problem. I think it's caused by the new version of `Android Studio` because with the old versions I didn't have this problem, so I vote your question – Rick Dec 08 '13 at 23:14

2 Answers2

1

"You should add following code in onCreate() method.

getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setIcon(R.drawable.ic_launcher); "

0

I see the problem that you use AppTheme as parent for MyActionBar style and it causes circular dependency. MyActionBar -> AppTheme -> MyActionBar ... You should use android:Widget.ActionBar or similar as parent of your action bar theme.

Also there should be android:Theme.Holo.Light instead of android:Theme.Light as parent of AppBaseTheme.

Here is how your res/values/styles.xml file should look like:

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

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light"/>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="android:Widget.ActionBar">
        <item name="android:background">HEX COLOR</item>
        <item name="android:titleTextStyle">@style/MyTitleTextStyle</item>
    </style>

    <style name="MyTitleTextStyle" parent="AppTheme">
        <item name="android:textColor">#FFFFFF</item>
    </style>

</resources>
Josef Raška
  • 1,291
  • 10
  • 8