Usando PreferenceActivity y ActionBarActivity
¿Es posible usar ActionBarActivity junto con PreferenceActivity ? Básicamente, quiero usar el código siguiente:
getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Enables the "back" arrow
El problema es PreferenceActivity no contiene el método getSupportActionBar () y ActionBarActivity no contiene ningún método para administrar y mostrar las preferencias.
Si está dispuesto a convertir su PreferenceActivity en un PreferenceFragment hay una implementación basada en v4 de soporte Fragmento:
https://github.com/kolavar/android-support-v4-preferencefragment
Estoy usando yo mismo y funciona muy bien en conjunto con ActionBarActivity!
ActionBarCompat
la función aún no es compatible.
Cómo agregar barra de acción de la biblioteca de soporte en PreferenceActivity?
ActionBar se ha añadido en el HoneyComb puede utilizar el siguiente código:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) getActionBar().setDisplayHomeAsUpEnabled(true);
Para algunas personas quieren usar getSupportActionBar()
con PreferenceActivity
. Compilado con Android 6
Declare esto en su clase extends PreferenceActivity
private AppCompatDelegate mDelegate;
Y añada esto:
private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; }
Y llame a su barra de acciones:
android.support.v7.app.ActionBar actionBar = getDelegate().getSupportActionBar();