Membuat Toast

Layout
<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Toast"
        android:id="@+id/btn1"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />


Java
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btnKlik = (Button) findViewById(R.id.btnKlik);
        btnKlik.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "Ini yang namanya toast", Toast.LENGTH_LONG).show();
            }
        });
    }
}


Comments

Popular posts from this blog

Mengenal Satuan Ukuran sp dan dp di Android

Menjalankan Aplikasi Android