skip to Main Content

I want to change the font style, font size and positioning of the app name in my action bar to more to the centre, in android studio. I can’t find anything when looking up how to do this on the internet. Does anyone know how this is done? My app name is located in my String.xml file. This is currently the only line of code in this file:

    <resources>
    <string name="app_name">TestApp</string>
</resources>

In which file in my app do I add the code to change these characteristics regarding the app name in the actionbar at the top of the page and what is that code I need?

2

Answers


  1. Go to the styles.xml and add this code:

    <resources>
    <style name="CustomActionBar" parent="@style/Widget.AppCompat.ActionBar">
        <item name="android:layout_gravity">center</item>
        <item name="android:titleTextStyle">@style/CustomActionBarTitleText</item>
    </style>
    
    <style name="CustomActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textSize">20sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:typeface">monospace</item>
    </style>
    </resources>
    

    and then when you do that go to the AndroidManifest.xml and add this code:

    android:theme="@style/CustomActionBar"
    

    Finally in your java file add this:

    getSupportActionBar().setTitle(R.string.app_name);
    

    I hope this helps you and answer your question. Please let me know if you have any problem.

    By the way if styles.xml does not exist by default you have to create
    it.

    Login or Signup to reply.
  2. The more efficient way would be to remove the default status bar from your theme and create a custom toolbar. This way, you will create a toolbar according to your design.

    In themes.xml

    change this-

    <style name="Theme.MatricApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    

    to this-

    <style name="Theme.MatricApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    

    Then in your XML layout design your own toolbar.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search