So I am setting a custom title bar for all of my activities using the following code in the onCreate.
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(id);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
activityTitle = (TextView)findViewById(R.id.titleText);
if (activityTitle != null)
{
activityTitle.setText(title);
}
This sets the custom title bar correctly but I find that on the main launcher activity the name of the app shows in the title bar for a split second then changes to the title I set above. This only happens for the main entry point activity, all other activities show my custom title instantly. Any ideas why this would happen and how to fix?
Thanks
If you're saying that the default bar shows for a brief period of time before being replaced by your custom bar, you may be experiencing the same issue as here: Android: Custom Title Bar
The workaround there is to create a style that effectively hides the default title until your custom title is displayed. You may still get pop-in, but at least it won't be showing the wrong text.
Related
What is the difference between Activity Title and Action Bar Title. Both seem to occupy same area
however activity title is set using
getActivity().setTitle("abc")
and Action Bar Title by
getActivity().getActionBar().setTitle("abc")
Well, there is a difference,
When setting the action bar's title using the setTitle method of class ActionBar will only be displayed if DISPLAY_SHOW_TITLE is set or action bar is present in the activity.
However, the setTitle method of Activity class can be used to set title even when there isn't any action bar for that window.
This really makes a difference when you are using a screen readers such as Talkback or developing an app for users with disabilities. It simply makes your app more accessible.
There is no difference.you can set title using both calls. getActivity().setTitle() is use full to set title in all devices(all API levels)
getActionBar() Call requires API level 11,and its will set action bar text
setTitle() sets Title bar text
I would like to use the Spinner as view-switching controller at Action Bar in my Android app, just like the native mail app (see part #2 at Android Common App UI).
So far I have managed putting the Spinner in the action bar and populating it with array of strings (see screen shot here) by looking at the example code at Android Developers.
My questions are:
How can I hide the activity name "MyAcitivity" from the action bar so the Spinner gets more place?
How can I make Spinner displaying two lines, one for the title and other for subtitle? Just like in the native mail app.
Why is the item text in the Spinner black and not white as the rest of the text in action bar?
I'm developing for Android version 4.0 and later.
How can I hide the activity name "MyAcitivity" from the action bar so the Spinner gets more place?
Call setDisplayShowTitleEnabled(false) on the ActionBar for this activity.
How can I make Spinner displaying two lines, one for the title and other for subtitle? Just like in the native mail app.
Create layouts that have more than one line in them that you use with your SpinnerAdapter.
Why is the item text in the Spinner black and not white as the rest of the text in action bar?
Probably you need to use getThemedContext() on ActionBar to get the Context to use with your SpinnerAdapter constructor.
1.How can I hide the activity name "MyAcitivity" from the action bar so the Spinner gets more place?
in order to remove this title you should edit the activity tag in manifast to android:label=" "
do this in every activity you wish for
3.Why is the item text in the Spinner black and not white as the rest of the text in action bar?
you can create style for the text color like theme.holo.light and apply this theme to your activity
1) How can I hide the activity name "MyAcitivity" from the action bar so the Spinner gets more place?
If you are using a standard theme, you can just look for the "noTitleBar" version and add it
android:theme="#android:style/Theme.Light.NoTitleBar"
FYI: check this link, it contains more detailed info
2) How can I make Spinner displaying two lines, one for the title and other for subtitle? Just like in the native mail app
I really dont get what you wanna do. If u need a text above and one below a spinning icon, you can just create a linear layout (a vertical one) adding inside of it the 3 elements
3) Why is the item text in the Spinner black and not white as the rest of the text in action bar?
You can modify every element in your layout by editing the style you are using.
FYI: basic theme in android
I have an application which uses a custom title bar. However, when my application launches, I noticed that the default title bar is shown for a brief period of time. My problem is I don't want to show the default title bar while my application is loading. How do I hide the title bar while my application is loading so that there will be no hint of it and then show it afterwards?
So far, I tried the following solutions but none have worked:
Hide the title bar in XML and then set the custom title bar in code. (Problem encountered: I received an error message saying: "You cannot combine custom titles with other title features".)
In XML:
<item name="android:windowNoTitle">true</item>
In onCreate method:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
//... some code goes here
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_header);
Set the size of the title bar in XML to 0. Then change it's size via code later. (Problem encountered: I don't know how to set the size of title bar in code. Is it possible? I tried getWindow().setAttributes() and getWindow().setLayout() but both of them didn't worked.)"
In XML:
<item name="android:windowTitleSize">30dp</item>
Modify windowTitleBackgroundStyle and set a transparent drawable as background. (Problem encountered: The content of the title bar became invisible but a line below the title bar is still visible.)
In XML:
<!-- style used by windowTitleBackgroundStyle -->
<item name="android:background">#drawable/transparent</item>
Some explanations for what you've encountered, hopefully they help lead you in a direction you're happy with.
You've already seen that your theme is used to generate what you see during activity loading. What's happening is the system is generating a temporary/loading window based on your activity's theme as specified in your manifest while your process is still starting up. Your code may not even be running yet, and your own activity will have a different window. This is significant because a number of settings become locked in once the window's decor has been created, but you actually have two chances here. The window your activity uses hasn't been created yet when you see this loading state.
Setting no title in your theme isn't working because it maps to the window feature Window.FEATURE_NO_TITLE. This dominates over any other title window features you may request and once a feature is requested you can't un-request or remove it regardless of whether decor has been initialized yet.
As part of your theme, the title size is giving you predictable issues. Theme attributes can't be changed. However, which theme your activity is using can be changed before your window decor has been initialized. You can specify one theme in your manifest for the activity that will be used during loading and swap it out using setTheme on your activity. (Best place is probably in onCreate before setContentView, where you would otherwise request window features.)
Chances are the line below the title bar you're seeing is the android:windowContentOverlay - the drawable used to supply the drop shadow from the title bar over the content. On most devices the top edge of this shadow would probably appear as a line below the title bar area. You can set this to #null to get rid of the shadow entirely if you want.
What I've done is set the following in my 'application' tag in my manifest.
android:theme="#android:style/Theme.NoTitleBar"
And then, for each activity, I added
android:theme="#style/CustomTheme"
can you try to open application in full screen mode..then on load of application you can exit full screen.that way your title bar will not be visible while in full screen mode. This works in html.not sure if you can use this trick.
How do you remove the category bar that displays in the PreferenceScreen? I have my own custom view for that, so I want to get rid of it altogether.
Would this help? Android – Hidding the status and title bar of your application
A similar question has been posted before but no satisfying answers yet.. The question is simple. I am using a custom Title Bar in my application (in the form on an image having text). However, When I use a title for the Launcher (the text beneath the launcher icon), it automatically sets the text for activity title and displays it under my customized title bar. If I use setTitle(""); at the start of the application to remove the title text, even then it shows it for a second ; enough to be noticed and if I completely remove the title bar text then it also removes the launcher title as well.. The application_label in Manifest file has nothing to do with the launcher title. The launcher title is obtained from Activity title which is quite annoying for me..
Any useful suggestions??
I understand you have two title bars? One 'from Android' and the other is your custom bar?
You can hide the Android-bar by using android:theme="#android:style/Theme.NoTitleBar" in the relevant activity in the manifest.
Did you use setTitle("") BEFORE calling setContentView(R.layout.your_activity) ? If so, it shouldn't show the text defined in your manifest at all because the setTitle() method call should have finished before the view is displayed. I use the same method to change the Title Bar text (and still maintain the Launcher text as defined in the manifest).
I will agree that it's strange the Launcher text isn't based on the android:label tag of <application>. The workaround of calling setTitle() in onCreate (before setContentView()) should do the trick though.