Android - How to avoid delay when calling setTitle() in activity's onCreate() - android

The title of my SplashActivity is quite long, so appears truncated beneath the launch icon on the device's home screen.
I want a shorter title shown beneath the launch icon, but a longer title shown in the Activity's action bar.
So, to try and achieve this I have specified a shorter title in the manifest...
<activity
android:name=".SplashActivity"
android:label="#string/app_name_short"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...and I'm using...
setTitle(getString(R.string.app_name));
...in the onCreate() method of SplashActivity so that the full title appears in the action bar.
It works, but only after about a 1 second delay. (So when SplashActivity is displayed, it shows the short title for 1 second before changing to the longer title.)
Is there any way I can fix this or any known workaround?
I've also tried creating a PreSplashActivity (with a short title) as the launch activity, including code to immediately launch SplashActivity (with a long title), but PreSplashActivity is still displayed for 1 second (even though it doesn't call setContentView(), so I'm a bit stumped.
Any ideas?

In this post answered by mark Renouf made it know that intent-filters can have a label attribute If it's absent the label is inherited from the parent component

Have you looked at the new docs for API21, specifically Toolbar? http://developer.android.com/reference/android/widget/Toolbar.html
With the new Toolbar you include it in your layout file like any other view. A nice side effect of this is that the initial screen is blank and the action bar appears in sync with the rest of your content. This gives you the option to set the title and make any customizations necessary before it becomes visible.
Here's details about using AppCompat to support older versions, it includes a section on using Toolbar in your layout and setting it as the action bar: http://android-developers.blogspot.ie/2014/10/appcompat-v21-material-design-for-pre.html

Related

The up navigation arrow is not showing up in the app bar

I'm writing my first app. I've done some practicals with Google Codelabs and learned to add an up navigation arrow to the app bar. When I try it with my app the navigation arrow is not anywhere.
The only difference between the practical and my code is the theme, which I've tried to change but the app stops when I do because I am not using an AppCompat theme which I have not learned yet. But I do not know if the theme is the problem.
<activity
android:name=".Lists"
android:label="#string/title_activity_lists"
android:parentActivityName=".MainActivity"
android:theme="#style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.fourwomendev.simplyneatlist.MainActivity" />
</activity>
I expect a left pointing arrow to the left of the title of the activity Lists on the app bar, but there is not one.
I'm writing my first app. I've done some practicals with Google
Codelabs and learned to add an up navigation arrow to the app bar.
When I try it with my app the navigation arrow is not anywhere.
Because you are not using any Actionbar in your activity.
<activity
android:name=".Lists"
android:label="#string/title_activity_lists"
android:parentActivityName=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" //<-----no actionbar is
specified
>
.......
</activity>
Use one actionbar to get the left arrow.
In trying to work with errors from changing the theme I realized that the basic activity I chose when creating this activity is created with a toolbar in Java. So I took out the code that created the toolbar and the reference to the theme in XML and my up navigation arrow appeared.

Is there a callback for when the title bar is completely hidden?

In my app I've got an activity that's defined like this:
<activity android:name=".DocViewActivity"
android:theme="#android:style/Theme.Light.NoTitleBar.Fullscreen">
</activity>
What I see when starting this activity is, first the UI appears (quick, but animated), then the hiding of the title bar happens, (also quick, but animated).
What I want to do is wait for all of this to finish before proceeding. I've tried using an OnGlobalLayoutListener, but I think (though it's hard to confirm) that it's getting called before the title bar disappears.
So my question is, how can I know when the layout has finished and the title bar has disappeared?
You can try OnLayoutChangeListener on the title bar however I think all hiding animations will be done once you set it in onCreate what is the real purpose of this task?

Android: view is displayed before calling setContentView R.layout

I'm studing an app and debugging it. I set breakpoint on first line of onCreate in MainActivity. However, app action bar is displayed before the next line "setContentView(R.layout." and before "super.onCreate" is stepped over. In other app action bar is for some reason not displayed even after I step over "setContentView(R.layout." (however screen becomes white with only status bar). Apps both have activity_main.xml, manifests describe both as
<activity
android:name=".MainActivity"
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
View that is displyed before setContentView is called differs that it includes custom View class, I set breakpoints in it's constructors, they are called during setContentView.
Why one app shows action bar before setContentView and in second case action bar is not shown even right after setContentView?
Thank you!
Maybe this is related to theme attribute which is set in AndroidManifest.xml for that activity ?
Activity with normal theme (with toolbar/actionbar enabled) is showing with this toolbar even before setting layout to give perception of fast loading app.
While Activity with disabled toolbar/actionbar via theme is not showing it at the beginning till layout is really inflated and added.

Custom Title Bar in android studio for my contact app I have designed how id like it to look in photoshop

Hey all I'd like help in creating my app in android studio I am new to this so I'll do my best to try and help you all understand best into what I am trying to do.
I am going to post two pics of how my design should look and I can't seem to get the start of the title bar done. In android studio it always on all of the project start-ups puts a black title bar with a picture of an android and its all black id like it to be cleared of the photo and re colour'd into red and the title text center'd as in my design image.
any help would be much appreciated
this should show the two pictures of my design
While you can edit the xml to change the ActionBar, your best bet is going to be using the new Toolbar. A toolbar is a fully customizable ActionBar without a lot of the traditional constraints of it. You can treat the toolbar just like any other layout container and include layout elements inside like TextViews, etc.
After you have designed your toolbar in xml, you can simply set the toolbar to be your action bar by calling activity.setSupportActionBar(yourToolbar);
This is much more flexible and allows much more control over the look and feel than using the traditional action bar.
Action bar custom label
AndroidManifest.xml:
<activity
android:name="com.package.app.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>
You can change the android:label from your app name to your desired title for each activity you have.
Action bar background color
To change the action bar background, create a custom theme for your activity that overrides the actionBarStyle property. This property points to another style in which you can override the background property to specify a drawable resource for the action bar background.
Styling the Action Bar

android toolbar like facebook or gmail app

i need the same thing like the toolbar on the Facebook or gmail App (i also want it do disappear when scrolling down and appear when scrolled on top again)
The thing is, im using a ActionBar on the top of the App already, what i need is another toolbar on the bottom. I thought about using the new toolbar and place it on the bottom(is this possbile? i mean using ActionBar and toolbar? If yes can i place it on the bottom?
I also tried to add more buttons in my ActionBar and put splitWhenNarrow in my manifest but it doesnt work..it just gets "scrollable" icons :S
Heres how i tried it :
<activity
android:name="com.danny.pqapp."
android:label="#string/app_name"
android:theme="#style/pqBlue">
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow"
android:showAsAction="ifRoom"/>
</activity>
anyone has an idea how to solve my problem?

Categories

Resources