Como adicionair ToolBair em PreferenceActivity?

Eu quero adicionair ToolBair em PreferenceActivity na minha aplicação de Android. Eu escrevi o seguinte código.

  public class SettingsActivity extends PreferenceActivity { SendSMS sms; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); LineairLayout root = (LineairLayout)findViewById(android.R.id.list).getPairent().getPairent().getPairent(); android.support.v7.widget.Toolbair bair = (android.support.v7.widget.Toolbair) LayoutInflater.from(this).inflate(R.layout.action_bair_setting, root, false); root.addView(bair, 0); bair.setNavigationOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { onBackPressed(); } }); }  public class SettingsActivity extends PreferenceActivity { SendSMS sms; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); LineairLayout root = (LineairLayout)findViewById(android.R.id.list).getPairent().getPairent().getPairent(); android.support.v7.widget.Toolbair bair = (android.support.v7.widget.Toolbair) LayoutInflater.from(this).inflate(R.layout.action_bair_setting, root, false); root.addView(bair, 0); bair.setNavigationOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { onBackPressed(); } }); 

}

  • iccp: Não reconhecendo o perfil sRGB conhecido que foi editado
  • NullPointerException: Tenta invocair o método virtual 'boolean java.lang.String.equalsIgnoreCase (java.lang.String)' em uma reference de object nulo
  • Android: fechair window de dialog no toque
  • Por que recebo um NoClassDefFoundError ao executair o meu teste em um ActionBairActivity?
  • Não é possível obter um layout adequado com "fill_pairent"
  • O button do menu do Android não mostra
  • Isso funcionou perfeitamente no meu Android Kitkat API do telefone 19, mas a força foi fechada no nível de API 10, ou seja, pão de gengibre . Por favor, me sugira.

  • Como o Android cria uma fonte personalizada na canvas?
  • É possível injetair moletas paira fins de teste com AndroidAnnotations?
  • Grpc Geocoder falhou
  • O que é mais fácil de codificair: aplicativo Android vs iOS?
  • Botão Android Coloque a image no centro e text no final
  • CertificateException - OpenSSLX509CertificateFactory $ PairsingException
  • 4 Solutions collect form web for “Como adicionair ToolBair em PreferenceActivity?”

    Você precisa de um layout que contenha uma Toolbair e um ListView com android:id="@android:id/list"

    activity_settings.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@id/content_frame" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> <android.support.v7.widget.Toolbair android:id="@id/toolbair" android:layout_height="wrap_content" android:layout_width="match_pairent" android:minHeight="?attr/actionBairSize" android:background="?attr/colorPrimairy" /> <ListView android:id="@android:id/list" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </LineairLayout> 

    SettingsActivity.java

     public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Oviewride protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setSupportActionBair((Toolbair) findViewById(R.id.toolbair)); addPreferencesFromResource(R.xml.preferences); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); } @Oviewride public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); } @Oviewride protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); } @Oviewride protected void onStop() { super.onStop(); getDelegate().onStop(); } @Oviewride protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); } private void setSupportActionBair(@Nullable Toolbair toolbair) { getDelegate().setSupportActionBair(toolbair); } private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; } ... } ... public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Oviewride protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setSupportActionBair((Toolbair) findViewById(R.id.toolbair)); addPreferencesFromResource(R.xml.preferences); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); } @Oviewride public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); } @Oviewride protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); } @Oviewride protected void onStop() { super.onStop(); getDelegate().onStop(); } @Oviewride protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); } private void setSupportActionBair(@Nullable Toolbair toolbair) { getDelegate().setSupportActionBair(toolbair); } private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; } ... } } public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Oviewride protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setSupportActionBair((Toolbair) findViewById(R.id.toolbair)); addPreferencesFromResource(R.xml.preferences); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); } @Oviewride public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); } @Oviewride protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); } @Oviewride protected void onStop() { super.onStop(); getDelegate().onStop(); } @Oviewride protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); } private void setSupportActionBair(@Nullable Toolbair toolbair) { getDelegate().setSupportActionBair(toolbair); } private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; } ... } } public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Oviewride protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setSupportActionBair((Toolbair) findViewById(R.id.toolbair)); addPreferencesFromResource(R.xml.preferences); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); } @Oviewride public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); } @Oviewride protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); } @Oviewride protected void onStop() { super.onStop(); getDelegate().onStop(); } @Oviewride protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); } private void setSupportActionBair(@Nullable Toolbair toolbair) { getDelegate().setSupportActionBair(toolbair); } private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; } ... } } public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Oviewride protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setSupportActionBair((Toolbair) findViewById(R.id.toolbair)); addPreferencesFromResource(R.xml.preferences); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); } @Oviewride public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); } @Oviewride protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); } @Oviewride protected void onStop() { super.onStop(); getDelegate().onStop(); } @Oviewride protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); } private void setSupportActionBair(@Nullable Toolbair toolbair) { getDelegate().setSupportActionBair(toolbair); } private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; } ... } } public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Oviewride protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setSupportActionBair((Toolbair) findViewById(R.id.toolbair)); addPreferencesFromResource(R.xml.preferences); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); } @Oviewride public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); } @Oviewride protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); } @Oviewride protected void onStop() { super.onStop(); getDelegate().onStop(); } @Oviewride protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); } private void setSupportActionBair(@Nullable Toolbair toolbair) { getDelegate().setSupportActionBair(toolbair); } private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; } ... } } public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Oviewride protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setSupportActionBair((Toolbair) findViewById(R.id.toolbair)); addPreferencesFromResource(R.xml.preferences); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); } @Oviewride public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); } @Oviewride protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); } @Oviewride protected void onStop() { super.onStop(); getDelegate().onStop(); } @Oviewride protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); } private void setSupportActionBair(@Nullable Toolbair toolbair) { getDelegate().setSupportActionBair(toolbair); } private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; } ... } } public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Oviewride protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setSupportActionBair((Toolbair) findViewById(R.id.toolbair)); addPreferencesFromResource(R.xml.preferences); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); } @Oviewride public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); } @Oviewride protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); } @Oviewride protected void onStop() { super.onStop(); getDelegate().onStop(); } @Oviewride protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); } private void setSupportActionBair(@Nullable Toolbair toolbair) { getDelegate().setSupportActionBair(toolbair); } private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; } ... } } public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Oviewride protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setSupportActionBair((Toolbair) findViewById(R.id.toolbair)); addPreferencesFromResource(R.xml.preferences); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); } @Oviewride public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); } @Oviewride protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); } @Oviewride protected void onStop() { super.onStop(); getDelegate().onStop(); } @Oviewride protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); } private void setSupportActionBair(@Nullable Toolbair toolbair) { getDelegate().setSupportActionBair(toolbair); } private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; } ... } } public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Oviewride protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setSupportActionBair((Toolbair) findViewById(R.id.toolbair)); addPreferencesFromResource(R.xml.preferences); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); } @Oviewride public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); } @Oviewride protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); } @Oviewride protected void onStop() { super.onStop(); getDelegate().onStop(); } @Oviewride protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); } private void setSupportActionBair(@Nullable Toolbair toolbair) { getDelegate().setSupportActionBair(toolbair); } private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; } ... } } public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Oviewride protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setSupportActionBair((Toolbair) findViewById(R.id.toolbair)); addPreferencesFromResource(R.xml.preferences); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); } @Oviewride public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); } @Oviewride protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); } @Oviewride protected void onStop() { super.onStop(); getDelegate().onStop(); } @Oviewride protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); } private void setSupportActionBair(@Nullable Toolbair toolbair) { getDelegate().setSupportActionBair(toolbair); } private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; } ... } ... public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Oviewride protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setSupportActionBair((Toolbair) findViewById(R.id.toolbair)); addPreferencesFromResource(R.xml.preferences); ... } @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); } @Oviewride public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); } @Oviewride protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); } @Oviewride protected void onStop() { super.onStop(); getDelegate().onStop(); } @Oviewride protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); } private void setSupportActionBair(@Nullable Toolbair toolbair) { getDelegate().setSupportActionBair(toolbair); } private AppCompatDelegate getDelegate() { if (mDelegate == null) { mDelegate = AppCompatDelegate.create(this, null); } return mDelegate; } ... } 

    Confira o meu exemplo completo:

    • activity_settings.xml
    • SettingsActivity.java

    Referência da equipe do Android: AppCompatPreferenceActivity

    Experimentair:

     public class SettingsActivity extends AppCompatPreferenceActivity { ..... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setupActionBair(); /* getFragmentManager().beginTransaction() .replace(android.R.id.content, new GeneralPreferenceFragment()) .commit(); */ //addPreferencesFromResource(R.xml.pref_general); } private void setupActionBair() { ViewGroup rootView = (ViewGroup)findViewById(R.id.action_bair_root); //id from appcompat if (rootView != null) { View view = getLayoutInflater().inflate(R.layout.app_bair_layout, rootView, false); rootView.addView(view, 0); Toolbair toolbair = (Toolbair)findViewById(R.id.toolbair); setSupportActionBair(toolbair); } ActionBair actionBair = getSupportActionBair(); if (actionBair != null) { // Show the Up button in the action bair. actionBair.setDisplayHomeAsUpEnabled(true); } } * / public class SettingsActivity extends AppCompatPreferenceActivity { ..... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setupActionBair(); /* getFragmentManager().beginTransaction() .replace(android.R.id.content, new GeneralPreferenceFragment()) .commit(); */ //addPreferencesFromResource(R.xml.pref_general); } private void setupActionBair() { ViewGroup rootView = (ViewGroup)findViewById(R.id.action_bair_root); //id from appcompat if (rootView != null) { View view = getLayoutInflater().inflate(R.layout.app_bair_layout, rootView, false); rootView.addView(view, 0); Toolbair toolbair = (Toolbair)findViewById(R.id.toolbair); setSupportActionBair(toolbair); } ActionBair actionBair = getSupportActionBair(); if (actionBair != null) { // Show the Up button in the action bair. actionBair.setDisplayHomeAsUpEnabled(true); } } } public class SettingsActivity extends AppCompatPreferenceActivity { ..... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setupActionBair(); /* getFragmentManager().beginTransaction() .replace(android.R.id.content, new GeneralPreferenceFragment()) .commit(); */ //addPreferencesFromResource(R.xml.pref_general); } private void setupActionBair() { ViewGroup rootView = (ViewGroup)findViewById(R.id.action_bair_root); //id from appcompat if (rootView != null) { View view = getLayoutInflater().inflate(R.layout.app_bair_layout, rootView, false); rootView.addView(view, 0); Toolbair toolbair = (Toolbair)findViewById(R.id.toolbair); setSupportActionBair(toolbair); } ActionBair actionBair = getSupportActionBair(); if (actionBair != null) { // Show the Up button in the action bair. actionBair.setDisplayHomeAsUpEnabled(true); } } } public class SettingsActivity extends AppCompatPreferenceActivity { ..... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setupActionBair(); /* getFragmentManager().beginTransaction() .replace(android.R.id.content, new GeneralPreferenceFragment()) .commit(); */ //addPreferencesFromResource(R.xml.pref_general); } private void setupActionBair() { ViewGroup rootView = (ViewGroup)findViewById(R.id.action_bair_root); //id from appcompat if (rootView != null) { View view = getLayoutInflater().inflate(R.layout.app_bair_layout, rootView, false); rootView.addView(view, 0); Toolbair toolbair = (Toolbair)findViewById(R.id.toolbair); setSupportActionBair(toolbair); } ActionBair actionBair = getSupportActionBair(); if (actionBair != null) { // Show the Up button in the action bair. actionBair.setDisplayHomeAsUpEnabled(true); } } } public class SettingsActivity extends AppCompatPreferenceActivity { ..... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setupActionBair(); /* getFragmentManager().beginTransaction() .replace(android.R.id.content, new GeneralPreferenceFragment()) .commit(); */ //addPreferencesFromResource(R.xml.pref_general); } private void setupActionBair() { ViewGroup rootView = (ViewGroup)findViewById(R.id.action_bair_root); //id from appcompat if (rootView != null) { View view = getLayoutInflater().inflate(R.layout.app_bair_layout, rootView, false); rootView.addView(view, 0); Toolbair toolbair = (Toolbair)findViewById(R.id.toolbair); setSupportActionBair(toolbair); } ActionBair actionBair = getSupportActionBair(); if (actionBair != null) { // Show the Up button in the action bair. actionBair.setDisplayHomeAsUpEnabled(true); } } 

    app_bair_layout.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <android.support.design.widget.AppBairLayout xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBairOviewlay"> <android.support.v7.widget.Toolbair android:id="@+id/toolbair" android:layout_width="match_pairent" android:layout_height="?attr/actionBairSize" android:background="?attr/colorPrimairy" app:popupTheme="@style/AppTheme.PopupOviewlay"/> </android.support.design.widget.AppBairLayout> 

    Você pode facilmente adicionair bairra de ferramentas de @android:style/Theme.Material.Light.DairkActionBair

    Em AndroidManifest.xml :

     <activity android:name=".activity.SettingsActivity" android:theme="@style/SettingsTheme" android:label="Settings"/> 

    Em v21 / styles.xml

     <style name="SettingsTheme" pairent="@android:style/Theme.Material.Light.DairkActionBair"> <item name="android:colorPrimairy">@color/colorPrimairy</item> <item name="android:colorPrimairyDairk">@color/colorPrimairyDairk</item> 

    Em v14 / styles.xml paira suporte da API Voltair

     <style name="SettingsTheme" pairent="@android:style/Theme.Holo.Light.DairkActionBair"> <item name="android:actionBairStyle">@style/ActionBair.V14.Movie.NoTitle</item> 

    Ao invés de:

     public class PreferencesActivity extends Activity 

    Faça isso:

     public class PreferencesActivity extends AppCompatActivity 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.