In my program I have several activities. When I run the program, I have the name of application in Title bar (top of the screen).
How can I change this title with any text that I wish? I want to change the text of it for each activity.
Thanks
Put
setTitle(YOUR_ACTIVITY_NAME_HERE);
under onCreate method of your desired activity.
The title bar displays the property defined in android:label="" for each . If you'd like it to display the same name no matter the activity you could use android:label="#string/title_bar" which should point to a string that you've defined in res/values/strings.xml.
Related
Now I have my nifty custom title bar in its own XML layout file and I've got my custom theme and style XML files. From my Activity class I can invoke it and it looks great.
Problem is my app has 14 Activities, each with their associated layout file. If I want to see the same title bar appear across my app, i.e., in all my Activities, the two main strategies I've seen are:
Put a an <include layout="#layout/my_title_bar" /> for my title bar in every layout file
...or...
Change all my Activity classes to derive from some common Activity that invokes the new title bar
Before I go off and do one of these I just want to make sure there's no more "centralized' way of doing it, like, say, in the manifest. There's no need to declare the default title bar in every activity, and it doesn't seem right to have to make separate changes for each activity for an app-wide feature like a custom title bar.
Thanks in advance for any tips!
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 want to develop a title bar in android like this
Home Button - Left aligned
Application Title - At the center
Image Icon - Right Aligned
I am not sure how to do it.
I am a new user and hence not allowed to post the image here. Sorry for inconvinience.
To create a custom title bar, you need to do four things
Set up a relative layout specifying TextView for left, center text, and a ImageView aligned in the centre.
From the onCreate of the activity where the custom title is displayed, call requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
Call setContentView as usual.
Then you need to instruct that the layout of the custom title is to be put in place with the associated relative layout getWindow.setFeatureInt(Window.FEATURE_CUSTOMER_TITLE, R.layout.my_custom_title);
From there onwards, its a matter of obtaining the TextView and ImageView widgets via findViewById and calling the appropriate methods of the widget to suit the requirements.
There are two way for the change the title bar
1) Normal way,
you can Change the Title of each screen (i.e. Activity) by setting their Android:label
<activity android:name=".Hello_World"
android:label="This is the Hello World Application">
2) if you want to Customize title-bar, i.e. you Want to put Image icon and custom-text, then following this
LINK
When we define any activity in our manifest file there's a tag called android:label in which what we generally do is this android:label="#string/app_name"
So this string appears at the top of the screen and in case of honeycomb 3.0 it is always visible on the top in the Action Bar.
Now by default this text appears in white color, but my requirement is to add colors for certain parts of this text and to also make it appear in two lines.
eg.- The application name is - "Poe's The Raven". I want Poe's in one line and the Raven in next plus the word Poe's should be in yellow color.
Hope I made it clear.
Please let me know how can we achieve this.
Thanks in advance.
please check this ...
Custom title bar without padding (Android)
http://labs.makemachine.net/2010/03/custom-android-window-title/
Gradient styles
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.