Android custom button style: APi - < 21 and > 21 - attributes - android

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?

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?

you have to use background instead of backgroundtint

Related

Material design : coloring two buttons with two colors in Android

I've looked around for a proper way of handling the background color of Buttons in android 5.0 and the only solution I could find was to define a style for the Button in values-21/styles.xml :
<item name="android:colorButtonNormal">#2196f3</item>
Is this the only way of coloring a button, while preserving both its design and the ripple effect ?
If yes, It would imply that I have to define a custom theme for each Button which has a different color, really ???
N.B : My question doesn't relate to backwards compatibility and AppCompat, which has already been discussed a lot.
You can use the tint option to change coloring that way, instead of making a seperate theme for each button, you would just have each tinted a different color. See here: Material Design Drawables
Yes, you have to define a separate theme with colorButtonNormal for each color. You can set theme to your Button as following:
<style name="ColorButonButton" parent="Theme.AppCompat.Light">
<item name="colorButtonNormal">#color/newColor</item>
</style>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text"
android:theme="#style/ColorButonButton"/>

Custom buttonBarButtonStyle

In an APP i want an custom Text Color of Buttons because the Background which does no match quite well. All this is happening in an ButtonBar Style. I watched the Slides from Nick Butcher and read almost all SO questions there regarding this topic.
The below style changes the Text Color but the Button in not borderless. Im curious how this can be overridden without destroying the other attributes ?
<style name="CustomButtonBarButtonStyle" parent="android:attr/buttonBarButtonStyle">
<item name="android:textColor">#fff</item>
</style>
The APP uses API Level 15, so the general style is there.

Designing Android Themes

Can anyone tell me how I can change my apps theme from the default ones made available? Holo and Holo.Light get a bit boring after a while.
The likes of Facebook, Google+, BBC Weather, Viber, Vine and Twitter all look very professional and have their own theme whereas the app I'm developing looks quite boring.
Is it possible to change the font of the text in my app? I know it's possible to change the colour and size of it.
Another thing which would be useful to know would be how to change the colour of the action bar that is used for my app. Currently it's black but I wouldn't mind changing it to a different colour than those used by the Android default themes (e.g. purple, green, blue, etc)
Maybe you can share some tips on what you think works well for Android design?
You can generate a custom theme at http://jgilfelt.github.io/android-actionbarstylegenerator/
If you only want to change a few font an colors etc take a closer look at this (source:http://developer.android.com/guide/topics/ui/themes.html)
If you like a theme, but want to tweak it, just add the theme as the parent of your custom theme. For example, you can modify the traditional light theme to use your own color like this:
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#color/custom_theme_color</item>
<item name="android:colorBackground">#color/custom_theme_color</item>
</style>
(Note that the color needs to supplied as a separate resource here because the android:windowBackground attribute only supports a reference to another resource; unlike android:colorBackground, it can not be given a color literal.)
Now use CustomTheme instead of Theme.Light inside the Android Manifest:
<activity android:theme="#style/CustomTheme">

Mixing holo light and holo dark EditText in theme

I am using Holo dark as the theme of my app. However, there is part of it where I wish to use the EditText from holo light as the background is light in this part. I have tried doing it in themes. It worked when I did something similar for a button (we wanted to use the gingerbread style button):
<style
name="Theme.Banks" parent="Theme.Sherlock.ForceOverflow">
<item name="android:buttonStyle">#android:style/Widget.Button</item>
</style>
I tried doing the same with android:editTextStyle, but it does not affect the drawable. That is handled by the attribute android:editTextBackground. Looking into the code, I cannot just override this and point it at the light theme because it references a private drawable:
This is from themes.xml in the SDK:
<item name="editTextBackground">#android:drawable/edit_text_holo_dark</item>
So my question is how to do this?
Another use case might be wishing to use the EditText from gingerbread.
Any ideas?
You could grab the drawables that you need out of the the sdk res folder and include them with your own project then reference your own copy of the holo light drawables for that one EditText.
Seems inefficient, but I am not sure of any other way to get around your style issue.

Android Styling/Theming of just Search Dialog

tl;dr: White text style in app theme being picked up by search dialog, making search text invisible.
I'm struggling mightily with what seems like a trivial issue.
My app is using a dark background, and I've tweaked the text color to be brighter than the standard gray using #EEEEEE.
I've implemented a Search Dialog (pre-Honeycomb) and it works well, but the text in the search dialog picks up the same #EEEEEE so it is essentially invisible. Even the context menu displayed when I long press the search text picks up #EEEEEE, so the text there is invisible as well.
I'm tearing my hair out, and I'm running out of hair.
Style:
<style name="master" paret="#android:style/Theme.NoTitleBar">
<item name="android:textColor">#EEEEEE</item>
<item name="android:windowNoTitle">true</item>
</style>
Manifest:
<application android:icon="#drawable/icon"
android:label="#string/app_label"
android:theme="#style/master"
android:hardwareAccelerated="true"
android:debuggable="true">
The attribute android:textColor is not meant to be used inside theme styles, it is primarily useful in widget and text appearance styles.
If you want to change the general text colors through a theme, use instead the android:textColor* family of attributes. There are quite a few of them, and different Views use them differently, so it takes a bit of experimentation (or careful studying of the Android source code) to to get it all right. The android.R.attr documentation lists them all. Look for the attributes that begin with textColor....
To get you started, try this theme, it will behave better by not affecting the Search Dialog colors at all, which seems to be what you want. By the way, you don't need to set android:windowNoTitle to true in your theme as your parent theme does that already:
<style name="master" parent="#android:style/Theme.NoTitleBar">
<item name="android:textColorPrimary">#EEEEEE</item>
<item name="android:textColorSecondary">#EEEEEE</item>
<item name="android:textColorTertiary">#EEEEEE</item>
</style>
I got into the same problem as you. I've looked around for a solution but it seems that you just can't change the textColor of a dialog. My solution was creating a custom dialog based on this tutorial: http://blog.androgames.net/10/custom-android-dialog/
I extended this a lot based on the Android source code, always using the same method names etc to make it a bit easier.
It is not ideal, but as far as I know it's the best option...
EDIT: for your problem there might be a simpler solution: don't put the textColor into the theme, but put it in a style. I don't know how you're styling your app but I'm usually creating a "master-style" which all the others inherit from (direct or indirect). You could then put the textColor in there so all your standard dialogs will still have the standard textColor.

Categories

Resources