1

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.

richq
  • 55,548
  • 20
  • 150
  • 144
Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188

4 Answers4

2

There are two ways to change title bar for your activity:

  1. Design time (that is, change title in AndroidManifest.xml file).
  2. 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

Community
  • 1
  • 1
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
2

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");
Noby
  • 6,562
  • 9
  • 40
  • 63
1

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.

skynet
  • 9,898
  • 5
  • 43
  • 52
0

To add a title bar in Android Studio, follow these steps:

Open your project in Android Studio. In the Project pane on the left-hand side, navigate to the app > res > values folder. Right-click the values folder and select New > Values resource file. In the New Resource File dialog box, name the file styles.xml and click OK.

<?xml version="1.0" encoding="utf-8"?>
<resources><style name="AppTheme" 
parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowActionBar">true</item>
    <item name="android:windowTitleSize">35dp</item>
    <item name="colorPrimary">#FF00BF</item>
</style></resources>

Apply the new theme to your activity by adding the following attribute to your activity in the AndroidManifest.xml file:

android:theme="@style/AppTheme"

Go to main file and add after onCreate():

ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle("Home Activity");
hee
  • 1
  • 1