I wanted to customize the styles for my app's croutons. Set 4 colors for as many styles. This is my custom styles class
public class TapabookCroutonStyle {
public static final int DURATION_INFINITE = -1;
public static final Style ALERT;
public static final Style WARN;
public static final Style CONFIRM;
public static final Style INFO;
public static final int AlertRed = R.color.rojo_vivo;
public static final int WarnOrange= R.color.naranja_resplandeciente;
public static final int ConfirmGreen = R.color.verde_lima;
public static final int InfoYellow = R.color.amarillo_canario;
private static final int DURATION_SHORT = 3000;
private static final int DURATION_MEDIUM = 5000;
private static final int DURATION_LONG = 10000;
static {
ALERT = new Style.Builder()
.setDuration(DURATION_LONG)
.setBackgroundColorValue(AlertRed)
.setHeight(LayoutParams.WRAP_CONTENT)
.build();
WARN = new Style.Builder()
.setDuration(DURATION_MEDIUM)
.setBackgroundColorValue(ConfirmGreen)
.setHeight(LayoutParams.WRAP_CONTENT)
.build();
CONFIRM = new Style.Builder()
.setDuration(DURATION_MEDIUM)
.setBackgroundColorValue(ConfirmGreen)
.setHeight(LayoutParams.WRAP_CONTENT)
.build();
INFO = new Style.Builder()
.setDuration(DURATION_MEDIUM)
.setBackgroundColorValue(InfoYellow)
.setHeight(LayoutParams.WRAP_CONTENT)
.build();
}
}
Colors are set in the color.xml file
<color name="verde_lima">#aaee22</color>
<color name="rojo_vivo">#E8110F</color>
<color name="naranja_resplandeciente">#FF6600</color>
<color name="amarillo_canario">#FFCC00</color>
I use wrappers to call Croutons.
/** Crouton Wrappers **/
public void croutonAlert(int stringId){
Crouton.makeText(this, stringId, TapabookCroutonStyle.ALERT).show();
}
public void croutonAlert(String text){
Crouton.makeText(this, text, TapabookCroutonStyle.ALERT).show();
}
public void croutonInfo(int stringId){
Crouton.makeText(this, stringId, TapabookCroutonStyle.INFO).show();
}
public void croutonInfo(String text){
Crouton.makeText(this, text, TapabookCroutonStyle.INFO).show();
}
public void croutonConfirm(int stringId){
Crouton.makeText(this, stringId, TapabookCroutonStyle.CONFIRM).show();
}
public void croutonConfirm(String text){
Crouton.makeText(this, text, TapabookCroutonStyle.CONFIRM).show();
}
public void croutonWarn(int stringId){
Crouton.makeText(this, stringId, TapabookCroutonStyle.WARN).show();
}
public void croutonWarn(String text){
Crouton.makeText(this, text, TapabookCroutonStyle.WARN).show();
}
Since I'm using ActionBarSherlock, my appTheme inherits from that and not from holo. On a different app which used standar croutons it posed no problems. However, custom croutons here won't show. I tested it on a 2.2 custom ROM and on 4.2 (google version).
The only question I found about this subject is this Holo Colors on pre Holo Devices? and it doesn't deal with custom Styles (and the problem does not reproduce on "holo devices" unlike my case).
Does anyone know why the four styles show up as grey?
Edit: I just tested and regular (built-in) styles like Style.ALERT do show the proper colors... Also, I changed the colors references from R.color.mycolor to their value in R (eg: 0x7f06000c) since that's how the original Style class in Crouton library does it, and still the same translucent gray... I also checked the original holo_red_light to check the alfa values and added them to my custom colors
<color name="verde_lima">#FFaaee22</color>
<color name="rojo_vivo">#FFE8110F</color>
<color name="naranja_resplandeciente">#FFFF6600</color>
<color name="amarillo_canario">#FFFFCC00</color>
but still nothing.
You are using the method setBackgroundColorValue(...)
which expects an actual color value.
But you are providing a resource Id to this method.
You probably want to call setBackgroundColor(int resId)
which resolves the resource ids internally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With