0

button style rounded corners not working on android earlier than level 21 Note that I'm applying this style on the whole project

drawable edittext.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp">
    <solid android:color="#FFFFFF"/>
    <corners
        android:bottomRightRadius="15dip"
        android:bottomLeftRadius="15dip"
        android:topLeftRadius="15dip"
        android:topRightRadius="15dip"/>
</shape>

Styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/colorPrimary</item>
    <item name="android:buttonStyle">@style/App_ButtonStyle</item>
    <item name="editTextStyle">@style/App_EditTextStyle</item>

    <item name="android:spinnerStyle">@style/App_SpinnerStyle</item>
</style>
<style name="App_EditTextStyle" parent="@android:style/Widget.EditText">
    <item name="android:background">@drawable/edittext</item>
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:padding">5dip</item>
    <item name="android:gravity">right</item>


</style>

<style name="App_SpinnerStyle" parent="@android:style/Widget.Spinner">
    <item name="android:background">@drawable/edittext</item>
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:padding">5dip</item>
    <item name="android:gravity">right</item>


</style>
<style name="App_ButtonStyle" parent="@android:style/Widget.Button">
    <item name="android:background">@drawable/edittext</item>
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:padding">10dip</item>
    <item name="android:gravity">center</item>
    <item name="android:width">150dip</item>

</style>

also spinner style not applied,

This screenshot show how it on android API level 21+

button style

and the below picture shows how it be on earlier than level 21

-level 21

So any idea what is wrong with this style

Note that Widget.AppCompat.Button didn't solve the problem

gazzarzx
  • 51
  • 9
  • Possible duplicate of [Material effect on button with background color](https://stackoverflow.com/questions/26686250/material-effect-on-button-with-background-color) – an_droid_dev Feb 21 '18 at 09:28

1 Answers1

2

Instead of creating another styles.

use button background android:background="@drawable/edittext"

this worked for my in every API level.

007
  • 516
  • 1
  • 5
  • 17
  • i want it to be applied on the whole project not just one button, – gazzarzx Feb 21 '18 at 09:33
  • so when i want to change anything like color as example, it will affect all buttons – gazzarzx Feb 21 '18 at 09:34
  • write this on every button. So when you have to change the style you just have to edit edittext.xml – 007 Feb 21 '18 at 09:35
  • use change textColor="@color/name_of_color and store the name in color.xml – 007 Feb 21 '18 at 09:36
  • so when you use style every API may have some different functionality. So the stability or consistency you want may not be achieved. – 007 Feb 21 '18 at 09:40