Settings Activity
Settings Activity permette di aggiungere un layout in cui inserire le impostazioni della propria app.
Ecco come si presenta il file settings_activity.xml
Ecco come si presenta il file root_preferences.xml contenuto all'interno della cartella xml
Ecco come si presenta il file SettingsActivity.kt
Settings Activity permette di aggiungere un layout in cui inserire le impostazioni della propria app.
Ecco come si presenta il file settings_activity.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<FrameLayout | |
android:id="@+id/settings" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<PreferenceCategory app:title="@string/messages_header"> | |
<EditTextPreference | |
app:key="signature" | |
app:title="@string/signature_title" | |
app:useSimpleSummaryProvider="true" /> | |
<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" /> | |
</PreferenceCategory> | |
<PreferenceCategory 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dm.tutorialsettingactivity401 | |
import android.os.Bundle | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.preference.PreferenceFragmentCompat | |
class SettingsActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.settings_activity) | |
supportFragmentManager | |
.beginTransaction() | |
.replace(R.id.settings, SettingsFragment()) | |
.commit() | |
supportActionBar?.setDisplayHomeAsUpEnabled(true) | |
} | |
class SettingsFragment : PreferenceFragmentCompat() { | |
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | |
setPreferencesFromResource(R.xml.root_preferences, rootKey) | |
} | |
} | |
} |
Download Project | ![]() |
Download file APK | ![]() |
Visualizza su | ![]() |
Commenti
Posta un commento