-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomToast.java
More file actions
42 lines (32 loc) · 1.3 KB
/
CustomToast.java
File metadata and controls
42 lines (32 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.example.lenovo.employeetrackingsystem;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
public class CustomToast {
// Custom Toast Method
public void Show_Toast(Context context, View view, String error) {
// Layout Inflater for inflating custom view
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// inflate the layout over view
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) view.findViewById(R.id.toast_root));
// Get TextView id and set error
TextView text = (TextView) layout.findViewById(R.id.toast_error);
text.setText(error);
Toast toast = new Toast(context);// Get Toast Context
toast.setGravity(Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);// Set
// Toast
// gravity
// and
// Fill
// Horizoontal
toast.setDuration(Toast.LENGTH_SHORT);// Set Duration
toast.setView(layout); // Set Custom View over toast
toast.show();// Finally show toast
}
}