1) phone 버튼 추가
MainActivity.kt
<TextView
android:id="@+id/emergencyContactValueTextView"
style="@style/Value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="010-0000-0000"
android:layout_marginEnd="8dp"
app:layout_constraintBaseline_toBaselineOf="@id/emergencyContactTextView"
app:layout_constraintEnd_toStartOf="@+id/phoneImageView"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@id/guideLine" />
<ImageView
android:id="@+id/phoneImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_baseline_call_24"
app:layout_constraintBottom_toBottomOf="@id/emergencyContactValueTextView"
app:layout_constraintEnd_toEndOf="@id/nameValueTextView"
app:layout_constraintTop_toTopOf="@id/emergencyContactValueTextView" />
2) 레이어 추가
Add helpers > Layer
Layer 로 emergencyContactValueTextView 와 phoneImageView 묶기
<androidx.constraintlayout.helper.widget.Layer
android:id="@+id/emergencyContactLayer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="emergencyContactValueTextView,phoneImageView"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="165dp"
tools:layout_editor_absoluteY="247dp" />
3) 통화기능 추가 ( 암시적 intent )
명시적 intent
어느 화면으로 이동할 것인지, Activity 를 명명해준 경우
binding.goInputActivityButton.setOnClickListener
val intent = Intent(this, InputActivity::class.java)
startActivity(intent)
}
암시적 intent
전화를 할 수 있는 앱은 여러가지가 있다.
따라서 전화를 할 수 있는 앱을 실행하도록 해줘. 라고 할 것이다.
binding.emergencyContactLayer.setOnClickListener {
with(Intent(Intent.ACTION_VIEW)) {
val phoneNumber = binding.emergencyContactTextView.text.toString()
.replace("-","")
data = Uri.parse("tel:$phoneNumber")
startActivity(this)
}
}
4) 실행화면
5) 추가구현할 내용
체크박스 선택 및 미선택 시 글자 위치 동일하게 만들기
'안드로이드 앱(Kotlin|Java) > [2025~] 안드로이드 앱' 카테고리의 다른 글
Part1_Ch05_01 개요 및 학습목표 (0) | 2025.04.09 |
---|---|
Part1_Ch04_09 복습 및 한걸음 더 (1) | 2025.04.09 |
Part1_Ch04_07 데이터 삭제하기 (0) | 2025.04.09 |
Part1_Ch04_06 데이터 저장하고 불러오기 (0) | 2025.04.09 |
Part1_Ch04_05 응급의료 정보 UI 그리기 (3) (0) | 2025.04.09 |