Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 한국산업인력공단
- package-lock.json
- 가명정보처리
- 호이스팅
- 모듈러 연산
- package.json
- 디오판투스 알고리즘
- 국가인적자원개발컨소시엄
- 백엔드
- 곱셈 암호
- 개인정보보호위원회
- 덧셈 암호
- 유클리드_알고리즘
- 개인정보보호교육
- function scope
- 동적타이핑
- 한국정보보호산업협회기자단
- 한국정보보호산업협회
- 포너블
- 웹 프레임워크
- node.js
- pwnable.tw
- 개인정보보호
- 마감임박
- Writeup
- arrow function
- 무료교육
- 개인정보안전성
- 확장 유클리드 알고리즘
- 백엔드입문
Archives
- Today
- Total
짱짱해커가 되고 싶은 나
02-1. 여러 기능을 하는 버튼 애플리케이션 구현 본문
4가지 버튼이 있는 앱을 구현할 계획이다.
- 네이버 사이트 열기
- 119 걸기
- 갤러리 열기
- 앱 종료하기
> 버튼 생성 (activity_main.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">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strBtn1">
</Button>
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strBtn2">
</Button>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:text="@string/strBtn3">
</Button>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button4"
android:text="@string/strBtn4">
</Button>
</LinearLayout>
LinearLayout을 사용했는데 이 레이아웃은 뷰를 한 쪽 방향으로 쌓는다. ex) 가로, 세로
나는 버튼을 한 줄로 세울거기 때문에 orientation속성을 vertical로 설정했다.
그리고 각 button의 id를 지정하고 버튼의 문자열은 strings.xml에 저장되어있다.
> 버튼 문자열 생성 (strings.xml)
<resources>
<string name="app_name">BaseApp</string>
<string name="strBtn1">네이버 홈페이지 열기</string>
<string name="strBtn2">119 응급전화 걸기</string>
<string name="strBtn3">갤러리 열기</string>
<string name="strBtn4">종료</string>
</resources>
> 버튼 이벤트 지정 (MainActivity.java)
package com.example.baseapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button button1, button2, button3, button4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button)findViewById(R.id.button1);
button2 = (Button)findViewById(R.id.button2);
button3 = (Button)findViewById((R.id.button3));
button4 = (Button)findViewById((R.id.button4));
button1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.naver.com"));
startActivity(intent);
}
});
button2.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:/119"));
startActivity(intent);
}
});
button3.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media"));
startActivity(intent);
}
});
button4.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
finish();
}
});
}
}
'모바일' 카테고리의 다른 글
02-3. BaseApp2 구현 (0) | 2021.02.15 |
---|---|
02-2. Android 프로젝트 구성 (0) | 2021.01.28 |
02. 안드로이드 프로젝트 기본 틀 (0) | 2021.01.22 |
01. HelloAndroid (1) | 2021.01.22 |
00. 안드로이드 개요 (0) | 2021.01.04 |
Comments