Android modify actionbar title bar font size

1. First find the theme of the application or activity that needs to be modified in AndroidManifest.xml

Insert image description here

2. Rewrite actionBarStyle in the theme that needs to be modified.

Insert image description here

3. Add the style of actionbarStyle

Insert image description here
But how do we know what the parent should inherit at this time? This requires following the clue.
Follow the parent of the AppTheme of the application and touch the place where actionbarStyle is.

<style name="AppTheme" parent="@android:style/Theme.DeviceDefault.Settings">
<style name="Theme.DeviceDefault.Settings" parent="Theme.Material.Settings">

Finally, you can find the corresponding actionbarStyle in this class

<style name="Theme.Material">

Insert image description here
So the parent can inherit the style I framed in red, and the same goes for the parent of MyTitleTextStyle.

4. Modify the font of actionbar

Insert image description here
Note that the name here is "android:textSize", not "textSize"

Attach the code block at the end

    <style name="AppTheme" parent="@android:style/Theme.DeviceDefault.Settings">
        <item name="android:windowNoTitle">false</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowAnimationStyle">@style/Animation</item>
        <item name="android:actionBarStyle">@style/MyActionBarStyle</item>
    </style>

    <style name="MyActionBarStyle" parent="@android:style/Widget.Material.ActionBar.Solid">
        <item name="android:titleTextStyle">@style/MyTitleTextStyle</item>
    </style>
    <style name="MyTitleTextStyle" parent="@android:style/TextAppearance.Material.Title">
        <item name="android:textSize">25dp</item>
    </style>

Guess you like

Origin blog.csdn.net/tuhuanxiong/article/details/128145158
Recommended