Android Studio 3일차

2021. 11. 3. 14:25Android Development

안드로이드 버튼 색상 변경.

매니페스트 에서 테마를 변경 Theme.AppCompat.Light

 

// 안드로이드 visibility 속성.

// 안드로이드 padding,margin

// 속성 enable, clickable

// rotation.checkBox, scaleType

 

package com.example.test6;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
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);

        getSupportActionBar().setDisplayShowHomeEnabled(true);

        setTitle("초간단 계산기");

        Button btn1,btn2,btn3,btn4;

        btn1 = findViewById(R.id.button1);
        btn2 = findViewById(R.id.button2);
        btn3 = findViewById(R.id.button3);
        btn4 = findViewById(R.id.button4);

        EditText et1 = findViewById(R.id.editText);
        EditText et2 = findViewById(R.id.editText2);

        TextView answer = findViewById(R.id.textView);



        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String i = et1.getText().toString();
                int ii = Integer.decode(i).intValue();

                String j = et2.getText().toString();
                int jj = Integer.decode(j).intValue();
                Toast.makeText(getApplicationContext(),i+"+"+j,Toast.LENGTH_LONG).show();
                answer.setText("계산 결과 : "+(ii+jj));

            }
        });
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String i = et1.getText().toString();
                int ii = Integer.decode(i).intValue();

                String j = et2.getText().toString();
                int jj = Integer.decode(j).intValue();
                Toast.makeText(getApplicationContext(),i+"-"+j,Toast.LENGTH_LONG).show();
                answer.setText("계산 결과 : "+(ii-jj));
            }
        });
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String i = et1.getText().toString();
                int ii = Integer.decode(i).intValue();

                String j = et2.getText().toString();
                int jj = Integer.decode(j).intValue();
                Toast.makeText(getApplicationContext(),i+"X"+j,Toast.LENGTH_LONG).show();
                answer.setText("계산 결과 : "+(ii*jj));

            }
        });
        btn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String i = et1.getText().toString();
                int ii = Integer.decode(i).intValue();

                String j = et2.getText().toString();
                int jj = Integer.decode(j).intValue();
                Toast.makeText(getApplicationContext(),i+"/"+j,Toast.LENGTH_LONG).show();
                answer.setText("계산 결과 : "+(ii/jj));
            }
        });
    }
}

계산기 만들기 실습.

'Android Development' 카테고리의 다른 글

Android Studio 7일차  (0) 2021.11.09
Android Studio 6일차  (0) 2021.11.08
Android Studio 5일차  (0) 2021.11.05
Android Studio 4일차  (0) 2021.11.05
Android Studio 1,2일차  (0) 2021.11.01