0

I am getting android.util.AndroidRuntimeException when i am setting the theme using setTheme method. here is my code:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        isCustomScreen = getIntent().getBooleanExtra("isCustomScreen", false);

        if (isCustomScreen ) {
            setTheme(R.style.CustomTitleTheme);
            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        }

        setContentView(R.layout.sample_layout);
            if (isCustomScreen ) {
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
                    R.layout.custom_title_bar);
           }
}

Declaration of activity in Manifest file:

<activity
            android:name=".activities.MenuActivity"
            android:configChanges="orientation|keyboardHidden"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

I am getting following exception while running this code with isCustomScreen as true:

02-17 18:35:54.619: E/AndroidRuntime(5787): Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
02-17 18:35:54.619: E/AndroidRuntime(5787):     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:183)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2074)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2225)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:194)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at android.app.Activity.setContentView(Activity.java:1647)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at com.sample.activities.MenuActivity.onCreate(MenuActivity.java:39)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-17 18:35:54.619: E/AndroidRuntime(5787):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-17 18:35:54.619: E/AndroidRuntime(5787):     ... 11 more

I have tried removing the theme declaration from the manifest file and setting the theme in onCreate method:

setTheme(android.R.style.Theme_Translucent_NoTitleBar);

but on doing this i am not getting the activity with Translucent background when isCustomScreen as false

Please suggest what should i do.

Update: added details of custom theme:

<style name="CustomWindowTitleBackground">
        <item name="android:background">#000000</item>
    </style>

    <style name="CustomTitleTheme" parent="Theme">
        <item name="android:windowTitleSize">45dip</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
    </style>
mudit
  • 25,306
  • 32
  • 90
  • 132

1 Answers1

0
<i><application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        //do not write theme setting here 
        android:label="@string/app_name" >
        <activity
            android:name=".activity.loginPageActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" //set theme here
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".activity.HomePageFragmentActivity" >
        </activity>
</application></i>
Sudhi S
  • 256
  • 2
  • 5