美文网首页
Android ToastUtil

Android ToastUtil

作者: 人心所向便是阳光 | 来源:发表于2018-11-21 20:38 被阅读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>

相关文章

网友评论

      本文标题:Android ToastUtil

      本文链接:https://www.haomeiwen.com/subject/cirhqqtx.html