Search code examples
androidbackwards-compatibility

setting a common button style for older OS versions


I am setting a common button style for older android versions but this code is not working on Kitkat, apart from making another layout resource file is there a way i can give some particular style and fix this issue ?

       <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:buttonStyle">@style/RobotoButtonStyle</item>
       </style>

        // here is my custom button style

      <style name="RobotoButtonStyle" parent="Base.TextAppearance.AppCompat.Button">
            <item name="android:fontFamily">@font/roboto_regular</item>
            <item name="android:textAlignment">center</item>
            <item name="fontFamily">@font/roboto_regular</item>
            <item name="android:textColor">@color/colorWhite</item>
            <item name="android:background">@drawable/button_curved</item>
            <item name="android:textAllCaps">false</item>
        </style>

Solution

  • These were used for older versions of Android

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
       <item name="buttonStyle">@style/RobotoButtonStyle</item>
    </style>
    
    <style name="RobotoButtonStyle" parent="Base.TextAppearance.AppCompat.Button">
          <item name="android:fontFamily">@font/roboto_regular</item>
          <item name="android:textAlignment">center</item>
          <item name="fontFamily">@font/roboto_regular</item>
          <item name="android:textColor">@color/colorWhite</item>
          <item name="android:windowBackground">@drawable/button_curved</item>
          <item name="android:textAllCaps">false</item>
    </style>