Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom Toast
package com.codingwithsara.customtoast;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void showToast(View view) {
LayoutInflater layoutInflater = getLayoutInflater();
View customToastView = layoutInflater.inflate(R.layout.toast_layout, null);
((TextView)customToastView.findViewById(R.id.msg)).setText("Hello World!");
Toast toast = Toast.makeText(customToastView.getContext(), "", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setView(customToastView);
toast.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.