Toast增强库
StyleableToast
这也是一个Toast增强库。
- 设置背景颜色的吐司。
- 设置吐司和存档的圆角半径不同的形状。
- 设置吐司给你所有的透明固体或透明的吐司。
- 设置笔划宽度和中风颜色在你的吐司。
- 设置一个图标旁边的面包文本。
你的图标上设置一个旋转的动画效果(见下面的例子01) 从Api 16 +工作
效果如下:
使用
1,在app/build.gradle文件中添加如下代码:
compile 'com.muddzdev:styleabletoast:1.0.6'
2,布局文件:main.xml就是几个按钮就不贴出来了,直接上一个是动态刷新的那个布局和飞行模式:
飞行模式:ic_airplanemode_inactive_black_24dp.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#ffffff"
android:pathData="M13,9V3.5c0,-0.83 -0.67,-1.5 -1.5,-1.5S10,2.67 10,3.5v3.68l7.83,7.83L21,16v-2l-8,-5zM3,5.27l4.99,4.99L2,14v2l8,-2.5V19l-2,1.5V22l3.5,-1 3.5,1v-1.5L13,19v-3.73L18.73,21 20,19.73 4.27,4 3,5.27z"/>
</vector>
动态刷新: ic_autorenew_black_24dp.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#fff"
android:pathData="M12,6v3l4,-4 -4,-4v3c-4.42,0 -8,3.58 -8,8 0,1.57 0.46,3.03 1.24,4.26L6.7,14.8c-0.45,-0.83 -0.7,-1.79 -0.7,-2.8 0,-3.31 2.69,-6 6,-6zM18.76,7.74L17.3,9.2c0.44,0.84 0.7,1.79 0.7,2.8 0,3.31 -2.69,6 -6,6v-3l-4,4 4,4v-3c4.42,0 8,-3.58 8,-8 0,-1.57 -0.46,-3.03 -1.24,-4.26z"/>
</vector>
3,使用方式:
1>在styles.xml文件中添加样式:
<style name="StyleableToast">
<item name="android:textColor">@color/red</item>
<item name="android:colorBackground">@color/gray</item>
<!--<item name="android:fontFamily">fonts/dosis.otf"</item>-->
<item name="android:textStyle">bold</item>
<!--<item name="android:strokeWidth">2</item>-->
<!--<item name="android:strokeColor">@color/colorPrimary</item>-->
<!--<item name="android:radius">@dimen/toastRadius</item>-->
<item name="android:alpha">255</item>
<item name="android:icon">@drawable/ic_file_download</item>
</style>
使用:
case R.id.btn_toast_style_05 :
StyleableToast.makeText(this, "Picture saved in gallery", Toast.LENGTH_LONG, R.style.StyleableToast).show();
break;
2>,使用code:
private StyleableToast st;
case R.id.btn_toast_style_01 :
st = new StyleableToast(this, "加载中...", Toast.LENGTH_LONG);
st.setBackgroundColor(Color.parseColor("#ff5a5f"));
st.setTextColor(Color.WHITE);
st.setIcon(R.drawable.ic_autorenew_black_24dp);
st.spinIcon();
st.setMaxAlpha();
st.show();
break;
3> .Builder
private StyleableToast stBuilder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
stBuilder = new StyleableToast.Builder(this,"已关闭飞行模式")
.withBackgroundColor(Color.parseColor("#865aff"))
.withIcon(R.drawable.ic_airplanemode_inactive_black_24dp)
.withMaxAlpha()
.build();
}
...
case R.id.btn_toast_style_02 :
stBuilder.show();
break;
Github地址:https://github.com/Muddz/StyleableToast
下载地址:StyleableToast-master.zip