[안드로이드 스튜디오/코틀린] 비디오 뷰, 캘린더 뷰
VideoView
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:orientation="vertical"
tools:context=".MainActivity">
<VideoView
android:id="@+id/videoView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.kt
package com.shinyelee.android_study2
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebViewClient
import android.widget.MediaController
import android.widget.Toast
import com.shinyelee.android_study2.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
private var vBinding : ActivityMainBinding? = null
private val binding get() = vBinding!!
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
vBinding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
// 방법1
val videoPath = "android.resource://" + getPackageName() + "/" + R.raw.joinfail
binding.videoView.setVideoPath(videoPath)
// 방법2
// binding.videoView.setVideoURI(Uri.parse("https://www.radiantmediaplayer.com/media/bbb-360p.mp4"))
val mediaController = MediaController(this)
binding.videoView.setMediaController(mediaController)
mediaController.setAnchorView(binding.videoView)
binding.videoView.keepScreenOn = true
// binding.videoView.start()
// binding.videoView.pause()
// binding.videoView.seekTo(10000)
}
override fun onDestroy() {
vBinding = null
super.onDestroy()
}
}
CalendarView
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:orientation="vertical"
tools:context=".MainActivity">
<CalendarView
android:id="@+id/calendarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:minDate="01/01/2022"
android:maxDate="12/31/2022"/>
<!-- minData, maxData로 범위 설정(MM/DD/YYYY) -->
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.kt
package com.shinyelee.android_study2
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.shinyelee.android_study2.databinding.ActivityMainBinding
import java.util.*
class MainActivity : AppCompatActivity() {
private var vBinding : ActivityMainBinding? = null
private val binding get() = vBinding!!
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
vBinding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.calendarView.setOnDateChangeListener { calendarView, year, month, day ->
// 월(month)은 1이 아니라 0부터 시작하니 주의!
// println(year.toString() + "/" + month.toString() + "/" + day.toString())
}
val calendar = Calendar.getInstance()
// 기본값 세팅하기
calendar.set(2022, 5, 15)
binding.calendarView.setDate(calendar.timeInMillis)
}
override fun onDestroy() {
vBinding = null
super.onDestroy()
}
}
참고
반응형
'개발(Android) > android studio' 카테고리의 다른 글
[Android Studio/Kotlin] Seek Bar, Rating Bar (0) | 2022.05.10 |
---|---|
[Android Studio/Kotlin] Progress Bar (0) | 2022.05.09 |
[Android Studio/Kotlin] Views (1) Image View, Web View (0) | 2022.05.05 |
[Android Studio/Kotlin] Buttons (2) Radio Group, Radio Button, Image Button, Floating Action Button, Snack Bar (0) | 2022.05.04 |
[Android Studio/Kotlin] Buttons (1) Switch, Toggle Button, Check Box (0) | 2022.05.04 |