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
- Host: GitHub
- URL: https://github.com/lopspower/mytoast
- Owner: lopspower
- Created: 2013-07-08T17:43:47.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2021-07-21T09:09:32.000Z (about 4 years ago)
- Last Synced: 2025-06-03T18:17:53.595Z (4 months ago)
- Language: Java
- Size: 440 KB
- Stars: 39
- Watchers: 3
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
MyToast
=======
[](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).