반응형

Button

 

사용자가 버튼을 누를 때 발생하는 동작을 전달하는 텍스트 또는 아이콘 (또는 텍스트와 아이콘 모두)으로 구성

 

 

 

Button XML

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    ... />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/button_icon"
    android:contentDescription="@string/button_icon_desc"
    ... />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    android:drawableLeft="@drawable/button_icon"
    ... />

 

 

 

 

 

Button Event

<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/button_send"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send"
    android:onClick="sendMessage" />

 

 

1. android:onClick ( recommended )

 

/** Called when the user touches the button */
public void sendMessage(View view) {
    // Do something in response to button click
}

 

2. OnClickListener

Button button = (Button) findViewById(R.id.button_send);
button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // Do something in response to button click
    }
});

 

 

developer.android.com/guide/topics/ui/controls/button#java

 

Buttons  |  Android 개발자  |  Android Developers

A button consists of text or an icon (or both text and an icon) that communicates what action occurs when the user touches it. Depending on whether you want a button with text, an icon, or both, you can create the button in your layout in three ways: With

developer.android.com

 

 

 

 

(번외)

LongClick Event

 

버튼을 길게 눌렀을 때, Event 발생

 

        Button button = (Button) findViewById(R.id.button_send);
        button.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
            	// Do something in response to button click
                
                return true;
                // 이벤트 처리를 못했을 경우 false return
            }
        });
728x90
반응형
반응형

1. Toast Message : 안드로이드 팝업 메세지. ( 디버깅용으로 많이 사용 )

 

Context context = getApplicationContext();  // Context 
CharSequence text = "Hello toast!";  // 표시되는 메세지 
int duration = Toast.LENGTH_SHORT;  // 화면이 표시되는 주기 

Toast toast = Toast.makeText(context, text, duration);  // Toast 객체 정의
toast.show();  // show 

 

Default : 메시지 알림은 화면 하단에 표시되며 가로로 가운데

Gravity Method : 상수, x-좌표 오프셋 및 y-좌표 오프셋의 세 가지 매개변수를 사용.

 

예를 들어, 토스트 메시지를 왼쪽 상단에 표시하려면 Gravity를 다음과 같이 설정하면 됩니다.

 

toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);

 

 

 

 

 

2. Logcat : 앱과 관련된 로그 출력. ( System.out.print 용처럼 사용,  디버깅용)

 

 

private static final String TAG = "MyActivity";
...
String message = "Hello";
Log.d(TAG, message);

 

 

 

developer.android.com/guide/topics/ui/notifiers/toasts

 

토스트 메시지 개요  |  Android 개발자  |  Android Developers

토스트 메시지는 작은 팝업으로 작업에 관한 간단한 피드백을 제공합니다. 메시지에 필요한 공간만 차지하며 진행 중인 활동은 그대로 표시되고 상호작용도 유지됩니다. 토스트 메시지는 시간

developer.android.com

developer.android.com/studio/debug/am-logcat?hl=ko

 

Logcat을 이용한 로그 작성 및 보기  |  Android 개발자  |  Android Developers

Android 스튜디오에서 Logcat 창에 시스템 메시지를 표시하는 방법을 알아보세요.

developer.android.com

 

728x90
반응형

+ Recent posts