1

When I set the background color in the layout everything works perfectly. However, when I try to set the it from a theme it won't work. It seems I'm doing something wrong. Here is the code.

Manifest:

    <activity android:name="com.example.somma.MainActivity"
    android:label="@string/app_name"
    android:theme="@style/custom_title_theme"
    >
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity> 

custom_title_theme.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="custom_title_theme" parent="android:Theme">
    <item name="android:windowTitleSize">40dp</item>
    <item name="android:windowTitleBackgroundStyle">@drawable/custom_title_background</item>
    <item name="android:background">@color/Meerenguee</item>
</style>    
</resources>

Is that because in every class I call these lines onStart()?

      requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
      setContentView(com.example.somma.R.layout.sumwindow);
      getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);

custom_title_bar.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="@drawable/custom_title_background">

<TextView android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="16sp"
          android:textColor="@color/cream_brown"
          android:textStyle="bold"
          android:id="@+id/custom_title_text"
          android:text="@string/app_name"
          android:layout_centerInParent="true"
          android:shadowColor="@android:color/black"
          android:shadowRadius="3"/>

<Button android:id="@+id/settings_button" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentRight="true"
android:text="@string/settings"
android:onClick="openSharedPref"
android:background="@drawable/header_button"/>

</RelativeLayout>

Does getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar); prevents "custom_title_theme" from being set?

Here is a screen of how everything appears:

enter image description here

Pete B.
  • 3,188
  • 6
  • 25
  • 38
pinolo
  • 347
  • 2
  • 7
  • 20

2 Answers2

1

Add theme into your android manifeast file.

Your are missing @android:style.

use

android:theme="@android:style/custom_title_theme" instead of 
android:theme="@style/custom_title_theme"
Mohammod Hossain
  • 4,134
  • 2
  • 26
  • 37
1

I suggest you try following:

<application 
   android:icon="@drawable/icon" 
   android:label="@string/app_name" 
   android:theme="@style/custom_title_theme"/>
Ritesh Gune
  • 16,629
  • 6
  • 44
  • 72
  • the same here. If I do that I got this error "error: Error: No resource found that matches the given name (at 'theme' with value '@android:style/ custom_title_theme')." – pinolo Aug 26 '13 at 14:02
  • Now I get "You cannot combine custom title with other title features" – pinolo Aug 26 '13 at 14:10
  • Ok I found the answer for the bug http://stackoverflow.com/questions/15171373/you-cannot-combine-custom-title-with-other-title-features – pinolo Aug 26 '13 at 14:12
  • I did as you said but I had to create a different custom_title_style for API 11 and now it works as a charm! Thank you very much – pinolo Aug 26 '13 at 14:17
  • ok, I m glad that you got your answer. But a friendly suggestion, from next time onwards kindly provide as much details as possible with your question. – Ritesh Gune Aug 26 '13 at 14:20
  • 1
    Ok, I'll do that! Now that I read my question again I realize it lacks important informations. – pinolo Aug 26 '13 at 21:24