본문 바로가기

동방프로젝트

안드1일차

package com.example.helloandroid;

import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
Button button1;
Button btnNate;
Button btn199;
Button btnGal;
Button btnEnd;

@Override
protected void onCreate(Bundle savedInstanceState) {
//가장 먼저 시작하는 메소드 onCreate
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//setContentView: activity_main.xml을 화면에 표시하라는 의미

button1=(Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

//메세지를 잠시 출력해주는 메소드.
//파라미터== 메시지가 출력될 컨텍스트, 그 내용, 출력할 시간
Toast.makeText(getApplicationContext(), "버튼을 눌렀다",
Toast.LENGTH_SHORT).show();
}
});

btnNate=(Button) findViewById(R.id.btnNate);
btnNate.setBackgroundColor(Color.GRAY);
btnNate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.nate.com"));
startActivity(mIntent);
}
});

btn199=(Button) findViewById(R.id.btn911);
btn199.setBackgroundColor(Color.RED);
btn199.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent mIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("Intent.ACTION_VIEW, Uri.parse(\"tel:/911\""));
startActivity(mIntent);
}
});

btnGal=(Button) findViewById(R.id.btnGal);
btnGal.setBackgroundColor(Color.GREEN);
btnGal.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent mIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("content://media/internal/images/media"));
startActivity(mIntent);
}
});

btnEnd= (Button) findViewById(R.id.btnEnd);
btnEnd.setBackgroundColor(Color.BLUE);
btnEnd.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
finish();
}
});
}
}

 

/////////////////////////

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strBtn1"></Button>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnNate"
android:text="@string/strBtn2"></Button>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btn911"
android:text="@string/strBtn3"></Button>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnGal"
android:text="@string/strBtn4"></Button>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnEnd"
android:text="@string/strBtn5"></Button>

</LinearLayout>

///////////////////////////////

<resources> //문자열 저장용 헤더파일 비스무리한거
<string name="app_name">HelloAndroid</string>
<string name="strBtn1">버튼입니다</string>
<string name="strBtn2">네이트 홈페이지 열기</string>
<string name="strBtn3">911응급전화</string>
<string name="strBtn4">갤러리 열기</string>
<string name="strBtn5">끝내기</string>

</resources>

'동방프로젝트' 카테고리의 다른 글

안드3일차 -1  (0) 2020.08.11
안드2일차  (0) 2020.08.10
남방요척몽) 특별한 일 없으면 아직 바꿀 일 없을 player.cpp  (2) 2020.08.01
코틀린 2일차  (5) 2020.07.29
코틀린 1일차  (2) 2020.07.27