Guest User

Untitled

a guest
Dec 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <Preference
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:id="@android:id/widget_frame"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent"
  8. tools:context=".CustomPreference">
  9. <TextView
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content"
  12. android:text="This is a custom preference" />
  13. </Preference>
  14.  
  15. package com.example.myApp
  16.  
  17. import android.content.Context
  18. import android.support.v7.preference.Preference
  19. import android.support.v7.preference.PreferenceViewHolder
  20. import android.util.AttributeSet
  21. import com.example.myApp.R
  22. import com.example.myApp.R.layout.custom_preference
  23.  
  24. class CustomPreference (context: Context,
  25. attrs: AttributeSet? = null,
  26. defStyleAttr: Int = R.attr.preferenceStyle,
  27. defStyleRes: Int = defStyleAttr)
  28. : Preference(context, attrs, defStyleAttr, defStyleRes) {
  29. override fun onBindViewHolder(holder: PreferenceViewHolder?) {
  30. super.onBindViewHolder(holder)
  31. layoutResource = custom_preference
  32. }
  33. }
  34.  
  35. <?xml version="1.0" encoding="utf-8"?>
  36. <android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
  37. xmlns:app="http://schemas.android.com/apk/res-auto">
  38. <com.example.CustomPreference
  39. app:key="custom_preference_key"
  40. app:title="This is a custom preference" />
  41. </android.support.v7.preference.PreferenceScreen>
Add Comment
Please, Sign In to add comment