1

I want to create several button styles instyles.xml. I want to support API 19 and higher so I would like to create button styles for both API. What I am doing:

I've created custom style in stylex.xml:

<style name="AppTheme.ButtonGreen" parent="android:Widget.Holo.Button">
    <iten name="android:textColor">@color/accent</iten>
    <item name="android:background">@color/primary</item>
</style>

In facy the color does not change. Can you help me with theming and give some basic attributes like: background color, text color etc. cause those does not work (only font color works).

I have also implemented style for v21 in styles (v21).xml:

<style name="AppTheme.ButtonGreen" parent="android:Widget.Material.Button">
    <item name="android:textColor">@color/primary</item>
    <item name="android:background">@color/text_icons</item>
</style>

But here I need font color, background color, elevation, font size etc. (only font color works).

Generally I guess I am doing something wrong. Can you guys help me style those buttons for different API?

anton86993
  • 638
  • 1
  • 9
  • 26

2 Answers2

0

Please read this article https://www.androidcookbook.com/Recipe.seam?recipeId=3307

and this issue on StackOverflow: How to create custom button in Android using XML Styles

I think the first one would be enough for your actual needs.

If you have question, please feel free to ask.

EDIT: if you still feel stuck - maybe it would be good to create an image and set it as ImageButton.

http://angrytools.com/android/button/

http://dabuttonfactory.com/

Or try to find issues abot using Material Design in lower APIs. This might be helpful: how to use material design features in api lower than 21 in eclipse?

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • I use `v7.AppCompatButton` but < 21 api the button does not save it's color. When I set background and tint color, above 21 it's ok but under 21 the button does not save it's shape and rounded corners. Is there any way besides colorButtonNormal in main theme to get desired color? – anton86993 Dec 10 '15 at 23:49
  • It's seems to be a problem with background compatibility. I've edited the post – piotrek1543 Dec 11 '15 at 07:20
0

you have to use background instead of backgroundtint

Muhammad Waqas
  • 64
  • 1
  • 10