2014-12-19 46 views
2

我使用Crouton lib(https://github.com/keyboardsurfer/Crouton)。使用自定义风格的面包房图书馆

现在,我想使用自定义样式而不是默认样式。我能怎么做 ?

Style.ALERT是默认样式。

Crouton.showText(this, "test", Style.ALERT); 

我想利用这个风格:

@styles:

<style name="CroutonGreen"> 
    <item name="android:layout_width">match_parent</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:background">@color/color_pressed_buy_an_item</item> 
    <item name="android:gravity">center</item> 

</style> 

回答

6

它说here

一般来说,你可以修改

显示时间 尺寸设置 选择文本NS显示 自定义视图 外观&消失动画 显示的图像

因为风格是一般的切入点调整面包丁,去看看自己有什么可以用它做。

您可以尝试修改类用下面的代码来改变背景颜色:

static { 
ALERT = new Builder() 
    .setBackgroundColorValue(holoRedLight) 
    .build(); 
CONFIRM = new Builder() 
    .setBackgroundColorValue(holoGreenLight) 
    .build(); 
INFO = new Builder() 
    .setBackgroundColorValue(holoBlueLight) 
    .build(); 
CUSTOM = new Builder() 
    .setBackgroundColorValue(myColor) 
    .build(); 

}

我没有测试它,但我认为它应该工作。

然后在下面的这个类有下面的代码:

public Builder() { 
    configuration = Configuration.DEFAULT; 
    paddingInPixels = 10; 
    backgroundColorResourceId = android.R.color.holo_blue_light; 
    backgroundDrawableResourceId = 0; 
    backgroundColorValue = NOT_SET; 
    isTileEnabled = false; 
    textColorResourceId = android.R.color.white; 
    textColorValue = NOT_SET; 
    heightInPixels = LayoutParams.WRAP_CONTENT; 
    widthInPixels = LayoutParams.MATCH_PARENT; 
    gravity = Gravity.CENTER; 
    imageDrawable = null; 
    imageResId = 0; 
    imageScaleType = ImageView.ScaleType.FIT_XY; 
    fontName = null; 
    fontNameResId = 0; 
} 

heightInPixels,widthInPixels,重力已设置正确根据你的风格。

最后,在您的应用程序中,使用Style.CUSTOM调用您的油煎面包块。

Crouton.showText(this, "test", Style.CUSTOM); 
+0

谢谢,坦佩!我爱烤面包块! :d – 2017-05-29 19:08:30