Android ToastUtil

2018-11-21  本文已影响0人  人心所向便是阳光

ToastUtil(工具类)

  public class ToastUtil {
  public static void  showToast(String msg){
      if (TextUtils.isEmpty(msg)){
        return;
      }
      Toast.makeText(APP.context,msg,Toast.LENGTH_SHORT).show();
  }
}

APP(初始化)

public class APP extends Application {
    /*重要*/
    public static Context context;
    @Override
    public void onCreate() {
        super.onCreate();
        context=this;
    }
}

AndroidManifest.xml(清单文件)

<application
        <!--重要-->
        android:name=".APP"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
</application>
上一篇 下一篇

猜你喜欢

热点阅读