android定义背景颜色图标透明度的,描边效果等样式的Toast

描述:

android定义背景颜色图标透明度的,描边效果等样式的Toast

应用截图:

Toast

 

源码:

Style your toast in styles.xml. All available attributes:

    <style name="StyledToast">

    <item name="android:textColor"></item>
    <item name="android:textStyle"></item> only bold!
    <item name="android:fontFamily"></item> For custom fonts just add the path -> fonts/myfont.ttf
    <item name="android:colorBackground"></item>
    <item name="android:strokeWidth"></item>   API 21+
    <item name="android:strokeColor"></item>   API 21+
    <item name="android:radius"></item>  radius for corners of the toast shape
    <item name="android:alpha"></item>   value between 0-255 where 255 is full solid
    <item name="android:icon">/</item>  drawable id of the icon. R.drawable.xx

    </style>

Pass your style resource in the constructor and call show(); and you’re done!

    StyleableToast.makeText(context, "Saving profile", Toast.LENGTH_LONG, R.style.StyledToast).show();

Usage with by code:

    StyleableToast st = new StyleableToast(this, "Updating profile", Toast.LENGTH_SHORT);
    st.setBackgroundColor(Color.parseColor("#ff5a5f"));
    st.setTextColor(Color.WHITE);
    st.setIcon(R.drawable.ic_autorenew_black_24dp);
    st.spinIconAnimation();  
    st.setMaxAlpha();
    st.show();

Installation

Add the depedency in your build.gradle. The library is distributed via jCenter

dependencies {
    compile 'com.muddzdev:styleabletoast:1.0.5'   
}

源码下载:https://github.com/Muddz/StyleableToast

未经允许不得转载:安度博客 » android定义背景颜色图标透明度的,描边效果等样式的Toast

赞 (0)
分享到:更多 ()

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址