cannot combine custom titles with other title feat

2019-08-31 14:12发布

问题:

I have created a custom title bar for one of my screen and trying to use the same concept in other ,but getting android.util.AndroidRuntimeException: You cannot combine custom titles with other title features .

Requirement:

styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="titleBarHeading" parent="@android:style/TextAppearance">
        <item name="android:textSize">17sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">#444444</item>
    </style>
        <style name="CustomWindowTitleBarBG">
            <item name="android:background">#323331</item>
        </style>
        <style name="TitleBarTheme" parent="android:Theme">
            <item name="android:windowTitleSize">35dip</item>
            <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBarBG</item>
    </style>
</resources>

manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.loginscreen"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        andrid:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        >
        <activity
            android:name="com.example.x.sampleapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.x.sampleapp.ItemActivity"
             />
        <activity
            android:name="com.example.x.sampleapp.ReminderActivity"
            android:theme="@style/TitleBarTheme" >        </activity>
    </application>
</manifest>

Java Class:

public class ReminderActivity extends Activity {
    Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.reminderlayout);
        context=this;
        ArrayList<GetReminder> list = (ArrayList<GetReminder>) getIntent().getSerializableExtra("reminderList");
        System.out.println("size is >>>"+list.size());

    }
}

even i added <item name="android:windowActionBar">false</item> seeing other posts

回答1:

public class ReminderActivity extends Activity {
    Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.reminderlayout);
        context=this;
        ArrayList<GetReminder> list = (ArrayList<GetReminder>) getIntent().getSerializableExtra("reminderList");
        System.out.println("size is >>>"+list.size());

    }
}

Solution for my post

Removing requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); from the activity and adding label to manifest for the activity like this:

  <activity
   android:name="com.example.sheetal.sampleapp.ItemActivity"
   android:label="ss"
   android:theme="@style/TitleBarTheme" />