我想爲我的應用程序的油煎麪包塊定製樣式。爲多種款式設置4種顏色。這是我的自定義樣式類爲什麼自定義油煎麪包塊樣式顯示爲灰色而不是指定的顏色?
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文件
<color name="verde_lima">#aaee22</color>
<color name="rojo_vivo">#E8110F</color>
<color name="naranja_resplandeciente">#FF6600</color>
<color name="amarillo_canario">#FFCC00</color>
我使用包裝調用蒜香設置。
/** 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繼承了而不是從holo繼承。在使用標準油炸麪包塊的不同應用程序中,它沒有任何問題。然而,這裏的自定義油炸麪包片不會顯示。我在2.2自定義ROM和4.2(谷歌版)上測試過它。
我發現這個問題的唯一問題是這個Holo Colors on pre Holo Devices?它不處理自定義樣式(和問題不會在「holo設備」上重現,不像我的情況)。
有誰知道爲什麼這四種樣式顯示爲灰色?我只是測試和像Style.ALERT常規(內置)樣式顯示正確的顏色... 此外,我將顏色引用從R.color.mycolor更改爲它們在R中的值(例如, :0x7f06000c),因爲這是在Crouton庫中的原始樣式類是怎麼做的,還是一樣半透明的灰色...... 我也查原來holo_red_light檢查阿爾法值,並將其添加到我的自定義顏色
<color name="verde_lima">#FFaaee22</color>
<color name="rojo_vivo">#FFE8110F</color>
<color name="naranja_resplandeciente">#FFFF6600</color>
<color name="amarillo_canario">#FFFFCC00</color>
但仍然沒有。
它的工作!我使用setBackgroundColorValue從[原始風格類](https://github.com/keyboardsurfer/Crouton/blob/master/library/src/de/keyboardsurfer/android/widget/crouton/Style.java)複製它,所以我仍然不明白爲什麼它適合它而不適合我。但它的作品,這是重要的:) – Frank 2013-02-22 12:37:47
原始風格類使用_color values_而不是_resource id's_ ;-) – keyboardsurfer 2013-02-22 12:47:00