웹뷰는 안드로이드 애플리케이션 안에서 웹브라우저를 띄울 수 있는 방법을 제공한다. xml레이아웃에서 엘리먼트로 정의한다. 웹뷰를 정의하여 사용할 때는 androidManifest.xml파일에 인터넷 접속 권한을 등록해야 한다. 웹뷰의 설정정보는 액티비티에서 getSettings()메서드를 이용해서 여러가지 설정을 할 수 있다. 그리고 이 getSettings()로 가져온 WebSettings 타입에는 setJavascriptEnabled(boolean b)라는 메서드가 존재하는데 자바스크립트를 허용 할 것인가를 지정하는 것으로 대부분의 웹사이트가 자바스크립트를 사용하니 이것은 항상 true로 설정해야 한다. 다음은 간단한 웹뷰 예제 코드이다. 에딧텍스트에서 주소를 입력하고 버튼을 터치하면 웹뷰영역에서 웹..
몇몇 기기 구성은 프로그램 실행 중에 변경될 수 있다. (예: 화면 방향 전환, 키보드 가용성 및 언어 변경)이러한 변경이 일어나는 경우 안드로이드는 액티비티를 다시 실행시키게 된다. 쉡게 말하면 수명주기 중에서 destroy가 호출되고 다시 실행되면서 onCreate를 다시 호출하는 것이다. 이 같은 상황을 '특정 구성에 대한 변경'이라 칭하고 정리하겠다. 안드로이드는 특정 구성 변경에 대해 직접 처리 할 수 있는 선택지로 configchanges라는 activity의 속성을 제공한다. 그러나 configchanges의 사용은 시스템이 리소스의 재구성을 도와주지 않기 때문에 특정 구성 변경으로 인한 재시작을 반드시 피해야 하는 경우가 아니라면 사용하지 않는 것이 좋다. configchanges는 and..
selector라는 엘리먼트를 사용하면 뷰를 선택했을 때와 안했을 때의 색상을 다르게 줄 수 있다. 마치 웹프로그래밍 시에 css에서 hover와 같은 효과라고 볼 수 있다. 우선 selector엘리먼트를 정의 할 xml 파일을 하나 만들어야 되니res/drawable 디렉토리에서 마우스 오른쪽을 클릭해서 resource파일 추가로 해서 만든다. selector_ex.xml 위가 selector의 기본 구조이며, 안에 item엘리먼트가 존재하는데 여기에서 어떤 상태에 따라서 색상을 줄 수 있는가를 지정할 수 있다. 상태의 목록android:state_enable : 사용 가능 상태android:state_selected : 선택 상태android:state_pressed : 클릭 상태 (눌려있는 경우)a..
git 프로그램이 설치되어 있음을 전제로 한다. 저장소로 사용하려는 디렉토리에 마우스 우클릭 후 git bash를 실행한다. git의 환경설정에서 username과 email을 등록한다.(github가입했을 때의 유저명과 이메일) $ git config --global user.name "유저명" $ git config --global user.email "이메일" 현재 폴더에 대해서 저장소로 등록해둔다.$ git init github에 올릴 임의의 파일을 등록해둔 저장소 폴더에 생성하거나 붙여 넣는다. 그리고 git에 추가하는 명령을 입력한다.(여기서는 파일을 index.java파일을 올린다고 해둔다.)$ git add "대상파일/폴더이름" $ git add index.java $ git add . 위..
사용자가 화면을 터치하거나 키(홈키, 음량 등)를 누르면 이벤트가 발생하고 다음 메서드가 호출된다. boolean onTouchEvent(MotionEvent event); boolean onKeyDown(int keyCode, KeyEvent event); boolean onKeyUp(int keyCode, KeyEvent event); 위와 같은 메서드들은 모두 Activity클래스에 정의되어 있다. 우리가 직접만드는 클래스는 모두 Activity의 서브클래스로 부터 상속받아 코딩하기 때문에 이 이벤트들을 오버라이딩 할 수 있다. 그리고 기존에 존재하는 뷰들에 대하여 이벤트를 사용하기 위해서 다음과 같은 리스너 인터페이스를 구현해서 이벤트를 발생 시킬 수 있다. View.OnTouchListener ..