How to add TitleBar in this android example? - android

I am new to implement the ListView with section.
I have use this application to implement the section to my list view.
Now I want to add the Titlebar that display the application page title. Then where do I have to make a change? In the xml file or in the Java file?
Please refer the example and let me tell what should I have to change to make Titlebar for my app.

Try this...
final Activity activity = this;
activity.setTitle("Settings");
if you disabled the title bar using, this.requestWindowFeature(Window.FEATURE_NO_TITLE);
remove it.
(OR)
Try this..
final Activity activity = this;
this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.settings);
activity.setTitle("Settings");

There are two ways to change title bar for your activity:
Design time (that is, change title in AndroidManifest.xml file).
By coding (that is, you can code to change the activity title).
Example for 1st:
you can Change the Title of each screen (i.e. Activity) by setting their Android:label inside the AndroidManifest.xml file:
<activity android:name=".Hello_World"
android:label="This is the Hello World Application">
</activity>
And yes, to display customized title bar for your activity, go through this answer: How to change the text on the action bar

In your AndroidManifest.xml file you have a section for each activity that looks like this
<activity
android:label="Your Activity"
android:name=".YourActivity" />
where the android:label tag defines what the text in the titlebar is.

Related

Project name bar in main screen

When reviewing my app, I noticed that the blue bar on the top and the text in the bar (the project name) does not fit in the app.
I tried changing the project name into a more relevant one by going into REFACTOR -> RENAME but it said 'can't rename root module.' every time I tried to.
Is there a way I can either delete the blue bar or change the text on it?
Are you familiar with the resources strings object? Let me know if this makes sense... Look at the image that I've included. Go to res/values/strings.xml and make the app_name tag be empty
<string name="app_name"></string>
Project name for Toolbar is defined in res/values/strings with key app_name by default.
In strings.xml, change app_name.
Or there's a setText method on the ActionBar class
To remove the bar depends on the theme used by that Activity (or if you explicitly show a Toolbar in the XML layout)
The name of your app is defined in your AndroidManifest.xml. Inside, you'll see an Application object, with a property of ApplicationName. Set this to whatever you want.
for remove top bar use in Manifest file :
<application ....
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
>
The title of the action bar (your blue bar on the top) is set inside you AndroidManifest.xml, inside the activity tag:
<activity
android:name=".activity.MainActivity"
android:exported="true"
android:label="#string/app_name" >
</activity>
A good practice is to refer to a string stored inside Strings.xml
<string name="app_name">My cool app</string>
getActionBar().setTitle("TITLE");
OR
getSupportActionBar().setTitle("TITLE");

How to change the customize Window title bar and its icon for multiple activities

I am able to customize the Window title bar and its icon by following the below Link :-
http://androidcodesnippetsblog.blogspot.in/2013/03/custom-window-title-bar-in-android.html
But I want to have different title for different activities running in the same project.Is there any way to fix from one particular xml to have title bar and icon for multiple activities.
just Set imageview and textview id in your custom layout and set dynamically its value in particular Activity
ImageView image=(Imageview)getWindow().findViewById(your image view id);
TextView title=(Textview)getWindow().findViewById(your image view id);
set image.setImageResource(...);
and title.settext(title);
Thats it....
Instead of having the theme on your application tag change it to your activity instead. For example:
<activity
android:theme="#style/themeForAcitivy"
android:name="MyActivity">
</activity>
You can also call getActionBar().setCustomView(R.layout.myCustomBar) on each activity to create a custom ActionBar view if that works for you too.

Android : How Do I use blank activity?

I'm beginning android programming slowly. I want to blank and white (page of all) theme .So I don't want to see this part of image.
image http://u1311.hizliresim.com/1h/m/upm9r.png
Add below line to your manifest application tag. It will remove from all activities and if you want to remove some of activity just copy and paste below code to activity tag.
android:theme="#android:style/Theme.NoTitleBar"
In your manifest, where the activity is declared, add the "android:theme" as below:
<activity
android:name="yourActivityName"
android:label="your label"
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
</activity>
You may want to use this in your Activity
//Delete title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Add this in your main activity:
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Hope this helps.
In your manifest, in the activity tag, write so:
android:theme="#android:style/Theme.Holo.Light.NoActionBar"

Android: How to set icon in title bar of Dialog activity?

I declared a dialog activity in my Manifest as follows:
<activity android:name=".myDialog"
android:label="#string/title_dlg"
android:icon="#android:drawable/ic_dialog_alert"
android:exported="false"
android:excludeFromRecents="true"
android:theme="#android:style/Theme.Dialog">
However, only the title's text appears in the title bar and the icon appears to be ignored.
Is there a way to also show the icon in the title bar?
Use this after your super.onCreate(savedInstanceState); call:
requestWindowFeature(Window.FEATURE_LEFT_ICON);
Then, set your contentView(R.layout.youLayout);
and then use this:
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.ic_dialog_alert);
The order is important.
I think using below line after super call will work
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
Keep in mind to place it before setting content view

REMOVE upper Border layout

I have develop app in which I set layout 480 * 320, it is starting from top. But my problem is there is one in build border are display when we take a new project and it is display in all activity. So I want to disable it.
Border like
So can you tell how can I remove it or hide it?
I think what you are trying to do is hide the TitleBar of the application. You can do that by changing the application theme.
Add android:theme="#android:style/Theme.Light.NoTitleBar" in the <application> tag of your manifest file.
Any theme with .NoTitleBar should do the trick.
use any one.
Manifest:
android:theme="#android:style/Theme.NoTitleBar"
Or
java:
requestWindowFeature(Window.FEATURE_NO_TITLE);
requestFeature(FEATURE_NO_TITLE);
in you activity's onCreate before setting the layout should remove it.
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

Categories

Resources