-1

If you use Android Studio and set up and application, it sets up the default title of the toolbar to be the name of the activity. Where is the code for that? Also, I want to orient the items in toolbar the way I would like them to be. Where can I write codes for that? Is it in the xml file of menu or in layout file of the activity? I've tried setting text to center in the layout of the activity but it doesn't work.

Jchoi
  • 51
  • 8

3 Answers3

1

You can change de title setting app_name in strings.xml file.

<resources>
    <string name="app_name">Toolbar Title</string>
</resources>
0

Where is the code for that?

is in the AndroidManifest.xml

<activity  
    android:name="com.example.loginandregisterapi.LoginActivity"  
    android:label="@string/app_name" >  <!-- THIS -->
    ...
</activity>  
Matias Elorriaga
  • 8,880
  • 5
  • 40
  • 58
0

If you use Android Studio and set up and application, it sets up the default title of the toolbar to be the name of the activity. Where is the code for that?

Take a look at your AndroidManifest.xml. You'll probably find two android:label attributes there: one for the application and another one for the launcher activity. And they'll be pointing to a single string resource @string/app_name, which is located in strings.xml of your module's res folder. You can change the app_name value or put the name right in android:label attribute. Label from <application> tag will be shown on the Settings screen while <activity> label will be put on your launcher. The same applies to android:icon attribute.

Also, I want to orient the items in toolbar the way I would like them to be. Where can I write codes for that? Is it in the xml file of menu or in layout file of the activity?

Yes, you can add Back button to the left of your title and all the option menu items will be sticked to the right. Back button should be added in you MainActivity.java after setting action bar: getSupportActionBar().setDisplayHomeAsUpEnabled(true). Put all your menu items in res/menu/menu_main.xml and they will appear on the right side of your toolbar.

I've tried setting text to center in the layout of the activity but it doesn't work.

Toolbar isn't designed to be customizable, so you'll need a bit of hacking. Take a look at this thread or implement custom view instead of default toolbar to match your requirements.

Additional reading.

Community
  • 1
  • 1
Andrew
  • 490
  • 3
  • 18