2

I' developing an android app and I need to use my custom title bar using a picture and two buttons. The thing is, immediately when I launch my app, during 1 or 2 seconds before my custom title bar appears, there is the ugly default one with "my application" displayed. The minimum targeted API is 15.

All the answers found on stack overflow didn't work, or succeed to make it disappear but was doing the same to my custom title bar.

Here is how I call it from my activity:

supportRequestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.topbarclassic);

Since my first view is a fragment I dont call SetContentView

And this is my custom styles.xml:

<resources>

    <style name="theme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowTitleSize">50dp</item>
        <item name="android:windowNoTitle">false</item>
    </style>

</resources>

Once again my custom title bar works properly. I just need to get rid of the default one displayed quickly when the app starts. Thanks a lot!

Virthuss
  • 3,142
  • 1
  • 21
  • 39

2 Answers2

1

if you use this style the activity will load without an action bar

<style name="theme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

Then you should really be using a toolbar to set the action bar. For example :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize" />

</RelativeLayout>

Then in your activity you can set the action bar like this:

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

Dont forget to set your them in your AndroidManifest.xml

    <activity
        android:name=".path.MyActivity"
        android:theme="@style/theme"/>
Eoin
  • 4,050
  • 2
  • 33
  • 43
  • Saddly it doesnt work, as I said I'm not calling setContentView(...); on my activity since my view appears in a fragment. I'll trying to put this in fragment to see if it works, By the way, what do I do with supportRequestWindowFeature(Window.FEATURE_CUSTOM_TITLE); and getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.topbarclassic); ? – Virthuss Sep 30 '15 at 03:30
  • delete them, they will not be needed, maybe also try make your activity extend AppCompatActivity – Eoin Sep 30 '15 at 03:34
  • Hem my bad, I mean the first bar still appears before the custom one – Virthuss Sep 30 '15 at 03:38
  • Does the theme appears under the and under the in the manifest? or just under the ? – Virthuss Sep 30 '15 at 03:44
  • it appears under both yes – Eoin Sep 30 '15 at 03:45
  • When I removed the name attribute under application, the "ugly default bar" lose its title. Should it mean that the error come from the app, trying to open its own title bar before I open mine in the activity? – Virthuss Sep 30 '15 at 03:46
  • When your app launches it loads a placeholder activty that you see before the main activity lauches to give the impression of loading faster – Eoin Sep 30 '15 at 03:49
  • So I think here is my trouble. I tried a piece of your code without adding any title bar after and the empty screen was still here, just without the title bar. So its means the title bar is not the problem but this pre-activity screen running before the main activity. It means that I have to find a way to open my activity ( which open a fragment ) directly, or without this white screen. Thanks for your help :) – Virthuss Sep 30 '15 at 03:52
  • its impossible to open the app without showing that screen first. It is possible to customise the screen and turn it into a kind of splash screen, if you not against that. – Eoin Sep 30 '15 at 03:56
  • I'm gonna try the splash screen! – Virthuss Sep 30 '15 at 04:14
  • I'll upvote it as it's useful, but as for my answer, its more a workaround than a real solution (but this is for my case, your answer should work for others). – Virthuss Sep 30 '15 at 04:25
  • thats all i can ask, best of luck – Eoin Sep 30 '15 at 04:27
0

If found a workaround for my problem using Modge's link about splashscreen.

It doesn't solve the problem itself but remains a good workaround.

I created a small activity in charge of the splash screen, avoiding the white first screen to stay for too long. Then this splash redirect on my main activity.

This is also useful in my case since I can start some connection process during the splash screen. You can follow this example: http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/

Virthuss
  • 3,142
  • 1
  • 21
  • 39