✍2021,2022/app(android studio)

앱만들기3 (ImaginView &Toast)

리촬리 2021. 7. 5. 16:03
728x90

추후 추가 공부 후 세부 작성예정


image View : 화면에 특정 자신이 원하는 이미지를 띄울수 있게 해주는것

@mimap : 아이콘을 모아놓음

src : 링크를 나타냄

토스트 메세지 : 밑에서 갑자기 통 튀어나오듯이 팝업메시지가 나옴

gravity사용:정렬하기 위해서

(android:gravity는 위젯자체로의 정렬 값을 지정해주는 것입니다.

android:layout_gravity는 위젯자체가 아닌 위젯을 감싸주고있는 레이아웃의 정렬 값을 지정해주는 것)

 

activitymain.xml

<?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="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="안녕하세요"
        />


    <EditText
        android:id="@+id/et_test"
        android:layout_width="200dp"
        android:layout_height="wrap_content"/>
    <Button
        android:id="@+id/btn_move"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="이동"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center">

    <ImageView
        android:id="@+id/test"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@mipmap/ic_launcher"/>




</LinearLayout>

mainactivity.java

package com.example.intentexample;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


    private Button btn_move;
    private EditText et_test;
    private String str;
    ImageView test;


    @Override
    protected void onCreate(Bundle savedInstanceState) { //Oncreate:안에있는구문을 쫙실행해라
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        et_test = findViewById(R.id.et_test);
        //str = et_test.getText().toString(); //입력창에 입력한값을 변수에저장,gettext가 스트링형태로 변환

        btn_move = findViewById(R.id.btn_move);//아이디를 찾아와서 btn무브에 저장
        btn_move.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                str = et_test.getText().toString();
                //sub로 가고싶음
                Intent intent = new Intent(MainActivity.this , SubActivity.class);
                intent.putExtra( "str", str);
                startActivity(intent); //액티비티 이동해주는 구문
            }
        });

        test = (ImageView)findViewById(R.id.test);
        test.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "앱만들기..귀찮다",Toast.LENGTH_SHORT).show();
            }//이미지를 클릭했을때 토스트 메시지가 띄워지는것
        });




    }
}

결과

1. 메시지띄우기

2. 가운데 정렬(근데 실행오류남)

728x90