-
-
Save codingwithsara/fa4c31cff40de4bd37b188c68f1cd04c to your computer and use it in GitHub Desktop.
Custom Toast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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