开发者

Custom titlebar - system titlebar being shown for a brief moment?

I've got a custom layout I want to use as the titlebar of my android app. The technique found (linked at the bottom) works, but the system titlebar is displayed before onCreate() is called. Obviously that looks pretty jarring, as for a moment the system titlebar is shown, then my custom titlebar is shown:

// styles.xml
<resources>
  <style name="MyTheme">
    <item name="android:windowTitleSize">40dip</item>
  </style>
</resources>

// One of my activities, MyTheme is applied to it in the manifest.
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.my_activity);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_header);
}

I could always 开发者_如何学运维hide the system titlebar and display my own in-line perhaps with each and every layout, but, that's not very friendly.

Thanks

http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/


I think it's a framework limitation. I had the same problem in some of my applications and the ultimate solution was for me to tell the framework I didn't want a title bar at all and then create my own in my layouts. The include directive made it bearable for me, e.g.:

<include layout="@layout/title" />

When I used requestWindowFeature(Window.FEATURE_NO_TITLE) in my activities, I would have the same issue, I'd see the system title bar briefly while the activity was being build when it first loaded.

When I switched to using a theme to tell the framework I didn't want a title, the problem went away and I now see my own title directly on first load. The styling is easy for that:

<style name="FliqTheme" parent="@android:Theme.Black">
    <item name="android:windowNoTitle">true</item>
</style>

I know this doesn't apply to your issue with the custom title, but like ptc mentioned, if you move your custom title into style/theme definitions (which you do by overriding the system title styles in your theme), I think you'll be on the right track.


The same problem happened to me today when I was trying to custom the title. I solved it by set the android:theme to android:style/Theme.NoTitleBar in the AndroidManifest.xml, and call setTheme() to the actual theme I want in my activity's onCreate callback function.


Try creating a custom theme style in XML and then set your activity's theme attribute in the AndroidManifest.xml file.

http://developer.android.com/guide/topics/ui/themes.html#ApplyATheme


The method through setting android:theme does not work for me, I have made it by adding the following code in onCreate() of my Activity subclass:

  getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜