반응형
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 | 31 |
Tags
- subscript
- string
- 웹뷰
- Swift
- ios
- SwiftLint
- swipe
- Firebase
- dictionary
- 문자열
- autolayout
- RxSwift
- UIButton
- Java
- gcd
- Alamofire
- Apple
- Android
- 라이트모드
- WebView
- UITabBarController
- UIScrollView
- Observable
- LazyHStack
- 다크모드
- github
- remote config
- NavigationLink
- Realtime Database
- SwiftUI
Archives
- Today
- Total
점진적 과부하 개발 블로그
Android Toast & Snackbar 본문
반응형
Android 버튼의 Event 처리
버튼 만들기
- 버튼을 하나 만들어줍니다.
<?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"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:onClick="onClicked"/>
</LinearLayout>
이벤트 처리 코드 생성
- 안드로이드 스튜디오에서 간편하게 이벤트 처리 코드를 생성 시켜줌
Toast
- Toast를 이용한 간단한 메시지 출력 코드
package com.indul;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClicked(View view) {
Toast.makeText(getApplicationContext(), "Button Clicked",
Toast.LENGTH_SHORT).show();
}
}
Snackbar
- Snackbar를 이용한 간단한 메시지 출력 코드
package com.indul;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.google.android.material.snackbar.Snackbar;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClicked(View view) {
Snackbar.make(view, "Snackbar",
Snackbar.LENGTH_SHORT).show();
}
}
실행화면
- 버튼을 눌렀을 때(Toast)
- Snackbar
반응형
'Android > Java' 카테고리의 다른 글
Android Splash Screen 화면 구현 (0) | 2022.06.05 |
---|---|
Android 13주차 Graphic (0) | 2022.05.30 |