본문 바로가기

Programing (프로그래밍)/Android Studio (안드로이드 스튜디오)

안드로이드스튜디오 ToastMessage 토스트메세지 ( AndroidStudio )

728x90
반응형

안드로이드스튜디오 ToastMessage 토스트메세지 ( AndroidStudio )

app-debug.apk
6.64MB

activity_main.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context=".MainActivity">
 
    <EditText
        android:id="@+id/edt"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
 
    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
 
</LinearLayout>
cs

 

MainActivity.java

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
package com.example.myapplication;
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 
public class MainActivity extends AppCompatActivity {
    Button btn;
    EditText edt;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        btn = findViewById(R.id.btn);
        edt = findViewById(R.id.edt);
 
        btn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, edt.getText(), Toast.LENGTH_SHORT).show();
            }
        });
    }
}
cs
728x90
반응형