본문 바로가기

프로그래밍/Android

(93)
상태바 알림 처리 상태바 알림 노티피케이션은 노티피케이션 객체와 관리자를 사용하게 된다. 노티피케이션 객체도 컨텍스트 객체에서 얻어올 수 있다. 이전에 포스팅한 alert, toast 와 같이 Context 의 getSystemService() 를 사용한다. 1. Notification 매니저 얻기 : 아래처럼 얻을 수도 있다. String ns = Context.NOTIFICATION_SERVICE; NotificationManger notiManager = (NotificationManager) getSystemService( ns ); 2. Notification 객체 생성 상태바 아이콘, 티커메시지, 발생 시간으로 구성되어 있다. CharSequence ticker = "Test"; Notification noti..
Toast View 만들기 이번엔 커스텀 토스트 뷰를 만들어 볼 예정. 의례 하는데로 xml 레이아웃을 구성한다. 다이얼로그와 같이 토스트뷰를 위한 레이아웃을 별도로 구성하고, 해당 레이아웃에 원하는 뷰들을 배치한다. toast_layout.xml로 레이아웃을 생성한다. 레이아웃 구성이 끝나면, 소스코드에서 호출해 사용하면 된다. 다이얼로그와 같이 LayoutInflater 객체를 사용해 xml로 부터 레이아웃을 얻어와 사용한다.(getLayoutInflater() 혹은 getSystemService() 사용) LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate( R.layout.toast_layout, (ViewGroup) findViewBy..
AlertDialog 만들기 AlertDialog 는 일반적인 알림 대화상자에서 가장 범용적으로 사용되는 폼을 가지고 있다. 요녀석은 다른 다이얼로그와 조금 다르게 생성하고, 설정을 해야 하는데.. AlertDialog.Builder 를 통해 레이아웃을 붙이거나 설정을 조절할 수 있다. 1. 레이아웃 생성 다이얼로그로 사용할 레이아웃을 하나 만든다.. 기타 원하는 View를 추가한다. 2. AlertDialog // AlertDialog 객체 선언 AlertDialog.Builder builder; AlertDialog alertDialog; // Context 얻고, 해당 컨텐스트의 레이아웃 정보 얻기 Context context = getApplicationContext(); LayoutInflater inflater = (La..
Button 오브젝트 기본 레이아웃 이미지아이콘 추가 android:drawableLeft="@drawable/image" android:drawableRight, android:drawableTop, android:drawableBottom 텍스트와 이미지 간격 설정 android:drawablePadding="10dp" 소스상에서의 레이아웃 구성 Drawable icon = Drawable.createFromPath( "/data/icon/image.png" ); icon.setBounds( 0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight() ); Button button = new Button( this ); button.setText("Hello, I am a But..
Intent 기본사항 Intent 는 안드로이드에서 메시지를 전달하는 방법 중 하나이다. 서로 다른 Activity 간에 메시지 혹은 이벤트를 전달할 수 있다. (액티비티만을 해당하는 것이 아닌 백그라운드로 구동되는 서비스나 이벤트 수신을 기다리는 리시버들 에게도 메시지를 보낼 수 있다.) 관련함수 startActivity() startActivityForResult() startService() sendBroadcast() sendOrderedBroadcast() sendStickyBroadcast() Intent 객체는 이러한 메시지를 전달하기 위한 요소인데, 전달하는 형태에 따라 구성이 약간 달라진다. 1. 엑티비티의 실행 : 명시적호출 - 각 액티비티에 대해 해당 객체를 명확히 기술한다. Intent 객체의 생성자 :..