0

I recently created an application that uses a custom font pack in the whole app. But when I use the ActionMode, the title does not use the custom font. So does anyone know how I can apply a custom font to the title of the ActionMode?

The font of the Action Mode title does not match the other TextViews in the app.

See the picture below

https://photos.app.goo.gl/cP1uuHkzHkWshabY7

Ellen Spertus
  • 6,576
  • 9
  • 50
  • 101

2 Answers2

0

You can change actionMode title font using custom actionMode style

first create custom style

<style name="ActionMode" parent="@style/Widget.AppCompat.ActionMode">
    <item name="titleTextStyle">@style/ActionMode.Title</item>
    <item name="android:titleTextStyle">@style/ActionMode.Title</item>
</style>
<style name="ActionMode.Title" parent="@style/TextAppearance.AppCompat.Widget.ActionMode.Title">
    <item name="android:textColor">your color</item>
    <item name="fontFamily">@font/yourfont</item>
    <item name="android:fontFamily">@font/your font</item>
    <item name="textSize">15sp</item>
    <item name="android:textSize">15sp</item>
</style>

Now put in to your main style style.xml

<style name="Theme.Tarif.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="windowActionModeOverlay">true</item>
    <item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="p">shortEdges</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="colorPrimary">@color/light_primary</item>
    <item name="colorPrimaryDark">@color/light_primary</item>
    <item name="colorAccent">@color/green_500</item>
    <item name="android:windowBackground">@color/light_primary</item>

    <!--ActionMode-->
    <item name="actionModeStyle">@style/ActionMode</item>

</style>
Tarif Chakder
  • 1,708
  • 1
  • 11
  • 10
-1

I will search for 'Theme' related properties to change the actionbar font as I believe it is linked to that. Here is a link to a similar problem: How can I customize the Action Mode's color and text?

It uses 'Size' attribute to do the job.

<style name="Widget.ActionMode">
<item name="android:background">?android:attr/actionModeBackground</item>
<item name="android:backgroundSplit">?android:attr/actionModeSplitBackground</item>
<item name="android:height">?android:attr/actionBarSize</item>
<item name="android:titleTextStyle">@android:style/TextAppearance.Widget.ActionMode.Title</item>
<item name="android:subtitleTextStyle">@android:style/TextAppearance.Widget.ActionMode.Subtitle</item>
</style>
Damandroid
  • 756
  • 9
  • 31