Skip to content

liying2008/ApplicationToast

Repository files navigation

ApplicationToast

使用Application作为Context的Toast,具有即时显示的特性。

Download Demo Apk

引入(Download)

Use Gradle

compile 'cc.duduhuo.applicationtoast:applicationtoast:0.3'

Or Maven

<dependency>
  <groupId>cc.duduhuo.applicationtoast</groupId>
  <artifactId>applicationtoast</artifactId>
  <version>0.3</version>
  <type>pom</type>
</dependency>

使用(Usage)

第一步(The First Step)

在应用的Application类的onCreate方法中初始化AppToast类。如下:

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        AppToast.init(this);
    }
}

注意:不要忘记在AndroidManifest.xml文件中的application节点下配置android:name属性。

第二步(The Second Step)

尽情使用。

AppToast.showToast("Toast 1");
AppToast.showToast(R.string.toast2);
AppToast.showToast("Toast 3", Toast.LENGTH_LONG);
AppToast.showToast(R.string.toast4, Toast.LENGTH_SHORT);
Toast toast = AppToast.getToast();
toast.setGravity(Gravity.TOP | Gravity.CENTER, 0, 0);
toast.setText("自定义Toast");
toast.setDuration(Toast.LENGTH_SHORT);
toast.show();

方法说明(Methods)

方法名 返回值类型 备注
init(Application) void AppToast initialization
showToast(int) void Display Toast
showToast(CharSequence) void Display Toast
showToast(int, int) void Display Toast
showToast(CharSequence, int) void Display Toast
getToast() Toast Get a Toast object
getApplication() Application Get this Application

效果演示(Demo)

Demo

作者(Author)

李颖
新浪微博:@独毒火
邮箱:liruoer2008@yeah.net

日期(Date)

2016-12-09

License

Copyright 2016 LiYing

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.