How to add a button to a PreferenceScreen?

For the xml:

<Preference
    android:title="Acts like a button"
    android:key="@string/myCoolButton"
    android:summary="This is a cool button"
/>

Then for the java in your onCreate()

Preference button = findPreference(getString(R.string.myCoolButton));
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
    @Override
    public boolean onPreferenceClick(Preference preference) { 
        //code for what you want it to do 
        return true;
    }
});

This will appear like a normal Preference, with just a title and a summary, so it will look like it belongs.

Leave a Comment