简体   繁体   中英

Custom Title bar delay

My app uses a custom titlebar created as a layout and is implemented using this format:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.my_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_title);
super.onCreate(savedInstanceState);

Now it did not work using the regular theme android:Theme.Light , neither did android:Theme.Light.NoTitleBar , they both resulted in a fatal exception when setContentView was called. So I created a custom style which looks like this:

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

<style name="CustomTheme" parent="android:Theme.Light">
    <item name="android:windowTitleBackgroundStyle">@style/MyWindowTitleBackground</item>
    <item name="android:windowActionBar">false</item>
    <item name ="android:windowTitleSize">35dip</item>
</style>

However, every time the app is started there is a small delay in between the start and display of the actual layout with the custom titlebar, in this delay the default titlebar is shown with the appname in it. After about a second, when the Oncreate finishes, the custom title is loaded and shown.

Is there any way to fix this? What am I doing wrong?

Try putting

super.onCreate(savedInstanceState);

before the other lines and see if that works.

and putting

setContentView(R.layout.my_layout);

last. I seemed to remember my app crashing because I had it in the wrong order.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM