Created
December 24, 2019 06:31
-
-
Save jobinjj/fe33bc139744c34ecc70567594dca030 to your computer and use it in GitHub Desktop.
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
.... | |
public class MainActivity extends AppCompatActivity { | |
private Button btnSimpleToast,btnPositionedToast,btnCustomToast; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
.... | |
btnSimpleToast.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Toast.makeText(MainActivity.this, "Simple toast", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
btnPositionedToast.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Toast toast = Toast.makeText(MainActivity.this, "Po toast", Toast.LENGTH_SHORT); | |
toast.setGravity(Gravity.TOP|Gravity.RIGHT, 0, 0); | |
toast.show(); | |
} | |
}); | |
btnCustomToast.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
LayoutInflater inflater = getLayoutInflater(); | |
View layout = inflater.inflate(R.layout.custom_toast, | |
(ViewGroup) findViewById(R.id.container)); | |
Toast toast = new Toast(getApplicationContext()); | |
toast.setDuration(Toast.LENGTH_LONG); | |
toast.setView(layout); | |
toast.show(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment