Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 1차원 DP
- 2차원 dp
- 99클럽
- @Builder
- @GeneratedValue
- @GenericGenerator
- @NoargsConstructor
- @Transactional
- Actions
- Amazon EFS
- amazon fsx
- Android Studio
- ANSI SQL
- ApplicationEvent
- assertThat
- async/await
- AVG
- AWS
- Azure
- bind
- builder
- button
- c++
- c++ builder
- c03
- Callback
- case when
- CCW
- chat GPT
- CICD
Archives
- Today
- Total
기록
androidStudio/kotlin/preference 본문
index
(1) 의존성 주입 build.gradle (:app)
(2) SettingsActivity
(3) 화면구성 res/xml/root_preferences.xml
(4) add onClick listener
code
(1) 의존성 주입 build.gradle (:app)
plugins {...}
android {...}
dependencies {
...
// preference
implementation 'androidx.preference:preference-ktx:1.2.0'
}
(2) add SettingsFragment
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)
}
}
new>fragment/activity>Gallery.. 에서 선택하여 생성하는 것도 가능하다.
(3) 화면구성 res/xml/root_preferences.xml
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
app:title="@string/messages_header"
app:iconSpaceReserved="false">
<Preference
app:key="feedback"
app:title="feedback"
app:iconSpaceReserved="false"/>
<EditTextPreference
app:key="signature"
app:title="@string/signature_title"
app:useSimpleSummaryProvider="true"
app:iconSpaceReserved="false"/>
<ListPreference
app:defaultValue="reply"
app:entries="@array/reply_entries"
app:entryValues="@array/reply_values"
app:key="reply"
app:title="@string/reply_title"
app:useSimpleSummaryProvider="true"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
app:icon="@drawable/adv_ic_info"
app:title="@string/sync_header">
<SwitchPreferenceCompat
app:key="sync"
app:title="@string/sync_title" />
<SwitchPreferenceCompat
app:dependency="sync"
app:key="attachment"
app:summaryOff="@string/attachment_summary_off"
app:summaryOn="@string/attachment_summary_on"
app:title="@string/attachment_title" />
</PreferenceCategory>
</PreferenceScreen>
(4) add onClick listener
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)
}
override fun onPreferenceTreeClick(preference: Preference): Boolean {
when (preference.key){
"feedback" -> { // todo : sendEmail() }
}
return super.onPreferenceTreeClick(preference)
}
}
keyword
- app:iconSpaceReserved="false"
PreferenceFragmentCompat has padding on PreferenceCategory that I can't get rid of
- preference
https://developer.android.com/guide/topics/ui/settings?hl=ko
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xml에서의 import 기능
- 해당 위치에 있는 라이브러리를 각각 임의의 변수에 담아서 사용하겠다는 의미
- app은 변수명
result
reference
2020.09.29 - [안드로이드/예제] - androidStudio/java/preference:1.1.1 사용하기
'Moblie > Android' 카테고리의 다른 글
[issue] 이미지 해상도 처리하기 (0) | 2022.06.01 |
---|---|
AndroidStudio/java/ 멀티뷰 타입 Recyclerview (0) | 2022.05.29 |
디자인 패턴/java/Command Pattern (0) | 2022.05.20 |
[issue] ScrollView vs NestScrollView (0) | 2022.05.12 |
andriodStudio/다크 테마 지원하기 (0) | 2022.05.11 |
Comments