KotlinとPreference Libraryを用いてユーザー設定のあるアプリケーションを作ったのですが設定画面を閉じる方法がわかりません。
上にタイトルバーがそこのボタンを押すと戻る感じにしたいです
(見た目がダサいので設定画面以外ではタイトルバーは表示したくないです)
setting.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<CheckBoxPreference
android:defaultValue="true"
android:key="OnOff"
android:summaryOn="オン"
android:summaryOff="オフ"
android:title="OnOff" />
<ListPreference
android:defaultValue="OFF"
android:entries="@array/reply_entries"
android:entryValues="@array/reply_values"
android:key="level"
android:title="List preference"
app:useSimpleSummaryProvider="true" />
</PreferenceScreen>
Seeting.kt
package com.example.myapp
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.preference.PreferenceFragmentCompat
import com.example.sugoidentaku.R
class Setting : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
// res/xml/preferences.xml ファイルに従って設定画面を構成
setPreferencesFromResource(R.xml.setting, rootKey)
}
MainActivity.kt
supportFragmentManager
.beginTransaction()
.replace(R.id.setting,Setting())
.commit()