# dynamic-toasts **Repository Path**: chinasoft5_ohos/dynamic-toasts ## Basic Information - **Project Name**: dynamic-toasts - **Description**: 实现简单带有主题和图标的Dialog - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-17 - **Last Updated**: 2021-09-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # dynamic-Toasts #### 项目介绍 - 项目名称:dynamic-toasts - 所属系列:openharmony的第三方组件适配移植 - 功能:实现简单带有主题和图标的Dialog - 项目移植状态:主功能完成 - 调用差异:无 - 开发版本:sdk6,DevEco Studio2.2 beta1 - 基线版本:Release v4.1.0 #### 效果演示 ![](/image/action.gif) #### 安装教程 1.在项目根目录下的build.gradle文件中, ```gradle allprojects { repositories { maven { url 'https://s01.oss.sonatype.org/content/repositories/releases/' } } } ``` 2.在entry模块的build.gradle文件中, ```gradle dependencies { implementation('com.gitee.chinasoft_ohos:dynamic:1.0.0') ...... } ``` 在sdk6,DevEco Studio2.2 beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 #### 使用说明 使用该库非常简单,只需查看提供的示例的源代码MainAbilitySlice.java ``` DynamicToast.Config.getInstance() // Background color for default toast. .setDefaultBackgroundColor(@ColorInt int defaultBackgroundColor) // Tint color for default toast. .setDefaultTintColor(@ColorInt int defaultTintColor) // Background color for error toast. .setErrorBackgroundColor(@ColorInt int errorBackgroundColor) // Background color for success toast. .setSuccessBackgroundColor(@ColorInt int successBackgroundColor) // Background color for warning toast. .setWarningBackgroundColor(@ColorInt int warningBackgroundColor) // Custom icon for error toast. Pass `null` to use default icon. .setErrorIcon(@Nullable Drawable errorIcon) // Custom icon for success toast. Pass `null` to use default icon. .setSuccessIcon(@Nullable Drawable successIcon) // Custom icon for warning toast. Pass `null` to use default icon. .setWarningIcon(@Nullable Drawable warningIcon) // Disable icon for all the toasts. .setDisableIcon(boolean disableIcon) // Custom icon size in `pixels` for all the toasts. .setIconSize(int iconSize) // Custom text size in `SP` for all the toasts. .setTextSize(int textSize) // Custom text typeface for all the toasts. Pass `null` to use system typeface. .setTextTypeface(@Nullable Typeface textTypeface) // Custom background drawable for all the toasts. Pass `null` to use default background. .setToastBackground(@Nullable Drawable toastBackground) // Apply customisations. .apply(); ``` 调用 `reset()` 方法重置所有的设置项. ```java // Reset customisations. DynamicToast.Config.getInstance().reset(); ``` 另外,您可以根据不同的方法构建不同主题样式的Dialog。 ```java DynamicToast.make(context, "Default toast").show(); ``` ```java DynamicToast.make(context, "Default toast with duration", duration).show(); ``` ```java DynamicToast.make(context, "Default toast with icon", drawable).show(); ``` ```java DynamicToast.make(context, "Default toast with icon and duration", drawable, duration).show(); ``` ```java DynamicToast.makeError(context, "Error toast").show(); ``` ```java DynamicToast.makeError(context, "Error toast with duration", duration).show(); ``` ```java DynamicToast.makeSuccess(context, "Success toast").show(); ``` ```java DynamicToast.makeSuccess(context, "Success toast with duration", duration).show(); ``` ```java DynamicToast.makeWarning(context, "Warning toast").show(); ``` ```java DynamicToast.makeWarning(context, "Warning toast with duration", duration).show(); ``` ```java DynamicToast.make(context, "Custom toast", tintColor, backgroundColor).show(); ``` ```java DynamicToast.make(context, "Custom toast with duration", tintColor, backgroundColor, duration).show(); ``` ```java DynamicToast.make(context, "Custom toast with icon", drawable, tintColor, backgroundColor).show(); ``` ```java DynamicToast.make(context, "Custom toast with icon and duration", drawable, tintColor, backgroundColor, duration).show(); ``` #### 测试信息 CodeCheck代码测试无异常 CloudTest代码测试无异常 病毒安全检测通过 当前版本demo功能与原组件基本无差异 #### 版本迭代 - 1.0.0 #### 版权和许可信息 Copyright 2017-2021 Pranav Pandey Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.