skip to Main Content

I have one button and letterspacing is not working with it. Please check my following snippet code

 <style name="ButtonText_v2" parent="TextAppearance.AppCompat">
        <item name="fontFamily">@font/silka_regular</item>
        <item name="android:letterSpacing">0.1</item>
        <item name="android:textSize">@dimen/dimen_14dp</item>
    </style>

    <style name="PrimaryButton_v2" parent="Widget.AppCompat.Button">
        <item name="android:background">@drawable/button_selector_primary</item>
        <item name="android:textColor">@color/white</item>
        <item name="textAllCaps">true</item>
        <item name="textAppearance">@style/ButtonText_v2</item>
    </style>

layout.xml File

<Button
            android:text="Button"
            android:layout_height="56dp"
            android:layout_width="200dp"
            style="@style/PrimaryButton_v2"

            android:layout_margin="15dp"
            />

2

Answers


  1. You can’t apply letter spacing in button/custom button because their is some limitation in button component in which you can’t make text appearance and background customization and more limitation
    the solution for this is instead of button you can use text view and make custom text view it will also work similar to button and customize it according to requirement.
    for example :-
    https://stackoverflow.com/questions/9477336/how-to-make-a-custom-textview#:~:text=Create%20a%20Custom%20View%20for%20Textview.%20Make%20the,values%20Make%20entries%20of%20all%20fonts%20in%20strings.xml

    Login or Signup to reply.
  2. Add android:letterSpacing in PrimaryButton_v2 it will work perfectly.

            <style name="ButtonText_v2" parent="TextAppearance.AppCompat">
                <item name="fontFamily">@font/silka_regular</item>
                <item name="android:textSize">@dimen/dimen_14dp</item>
            </style>
        
            <style name="PrimaryButton_v2" parent="Widget.AppCompat.Button">
                <item name="android:background">@drawable/button_selector_primary</item>
                <item name="android:textColor">@color/white</item>
                <item name="textAllCaps">true</item>
                <item name="textAppearance">@style/ButtonText_v2</item>
                <item name="android:letterSpacing">0.1</item>
            </style>
    

    layout.xml File

    <Button
            android:text="Button"
            android:layout_height="56dp"
            android:layout_width="200dp"
            style="@style/PrimaryButton_v2"
    
            android:layout_margin="15dp"
            />
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search