为什么定制crouton样式出现在其指定的颜色为灰色,而不是? [英] Why do custom crouton Styles appear as grey instead of their specified color?

查看:254
本文介绍了为什么定制crouton样式出现在其指定的颜色为灰色,而不是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的应用程序的蒜香自定义样式。设置4种颜色尽可能多的风格。这是我的自定义样式类

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();
}
}

颜色是在color.xml文件中设置

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();
}

由于我使用ActionBarSherlock,我appTheme继承的,而不是从全息。在不同的应用程序,它使用STANDAR蒜香它不构成任何问题。但是,自定义蒜香这里将不会显示。我在2.2定制ROM和4.2(谷歌版本)进行了测试。

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).

我发现有关这一问题的唯一的问题是在$此全息颜色p $ P全息设备?的,它不使用自定义样式处理(和问题不会出现在全息设备不像我的情况重现)。

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?

编辑:我只是测试,并定期(内置)样式像Style.ALERT确实表现出正确的颜色... 另外,我改变了从R.color.mycolor颜色引用它们的价值在R(如:0x7f06000c),因为这是如何在Crouton库中的原始样式类做它,还是一样半透明的灰色... 我还检查了原holo_red_light检查的阿尔法值,并将其添加到我的自定义颜色

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.

推荐答案

您正在使用的方法 setBackgroundColorValue(...)它预计实际色彩值。 但是,你所提供的是资源ID此方法。

You are using the method setBackgroundColorValue(...) which expects an actual color value. But you are providing a resource Id to this method.

您可能需要调用 setBackgroundColor(INT渣油)这样就解决了内部的资源ID。

You probably want to call setBackgroundColor(int resId) which resolves the resource ids internally.

这篇关于为什么定制crouton样式出现在其指定的颜色为灰色,而不是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆