An open API service indexing awesome lists of open source software.

https://github.com/lopspower/mytoast

Custom Toast on Android
https://github.com/lopspower/mytoast

Last synced: 3 months ago
JSON representation

Custom Toast on Android

Awesome Lists containing this project

README

          

MyToast
=======
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-MyToast-green.svg?style=flat)](https://android-arsenal.com/details/1/2849)

Custom Toast on Android

Usage
-----

```java
MyToast.show(this, "MyToast Sample", true);
```

Create
-----

**toast_layout.xml** :
```xml

```

**MyToast.java** :
```java
package com.mikhaellopez.mytoast;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MyToast {
public static void show(Context context, String text, boolean isLong) {
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(R.layout.toast_layout, null);

ImageView image = (ImageView) layout.findViewById(R.id.toast_image);
image.setImageResource(R.drawable.ic_launcher);

TextView textV = (TextView) layout.findViewById(R.id.toast_text);
textV.setText(text);

Toast toast = new Toast(context);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration((isLong) ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
}
```

License
-----

MyToast by [Lopez Mikhael](http://mikhaellopez.com/) is licensed under a [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).