You cannot combine custom title with other title features

前端 未结 2 1291
攒了一身酷
攒了一身酷 2021-01-06 10:42

In my application, I\'m using ActionBarSherlock library. Also I\'m using a custom title bar. Here goes my onCreate:

requestWindowFeature(Window.FEATURE_CUSTO         


        
相关标签:
2条回答
  • 2021-01-06 11:13

    I had the same problem and solved it:

    THE ROOT CAUSE: In the Manifest, I copy pasted this tag by mistake from my splash screen into my activity: @android:style/Theme.NoTitleBar The fatal exception occured when I also requested a FEATURE_CUSTOM_TITLE on my activity, causing the conflict.

    SOLUTION: To fix it, I checked these 3 things: 1)OnCreate method:

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
            setContentView(R.layout.activity_login);
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_titlebar);
    
        }
    

    2)INSIDE your manifest.xml: Make sure a line such as these ONLY appears in a splash screen if you have one: android:theme="@android:style/Theme.NoTitleBar REMOVE that line from any other activity if you want a custom Bar.

    In the application tag , my only theme tag is this one: android:theme="@style/AppTheme"

    In the activity tag, I have no theme tag.

    3) Go to your activity's XML layout, and view it in GRAPHIC LAYOUT mode. Maye sure your that the Theme says AppTheme (its the the you put on the manifest) Mine said "No Title", so this was causing the problem.

    0 讨论(0)
  • 2021-01-06 11:21

    I received the same exception.

    Here is what I found: In newer versions of Android, the framework will use the Window.FEATURE_ACTION_BAR feature whenever the Holo theme is selected. The framework throws the exception whenever an app calls setFeatureInt(Window.FEATURE_CUSTOM_TITLE) and FEATURE_ACTION_BAR has already been set.

    In my case, the styles.xml file in the values-v11 folder was redefining my theme to inherit from android:Theme.Holo. When I attempted to run my app on a Android 3.0 or above - it crashed because Holo uses the ActionBar by default. The fix was simple. Turn the ActionBar off when using Holo. Here is the revised values-v11\styles.xml changes:

    <style name="AppBaseTheme" parent="android:Theme.Holo.NoActionBar">
        <!-- API 11 theme customizations can go here. -->
    </style>
    
    0 讨论(0)
提交回复
热议问题