2

In my android app I have a default app theme which has no action bar since I am adding my own toolbar

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

So this works well with my other activities except settings activity, So as a quick fix I've decided to add a custom style for it via

<style name="SettingsMenu" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorBackground">@color/colorPrimaryDark</item>
    <item name="textColor">@color/colorAccent</item>
</style>

and also in the manifest I've added

<activity
        android:name=".backend.settings.SettingsActivity"
        android:theme="@style/SettingsMenu" //theme here
        android:label="@string/title_activity_settings">
</activity>

So in my settings activity which extends AppCompatPreferenceActivity i have

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setupActionBar();
}

/**
 * Set up the {@link android.app.ActionBar}, if the API is available.
 */
private void setupActionBar() {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        // Show the Up button in the action bar.
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}

So the above still doesnt show the toolbar.

I have also tried adding a custom toolbar via

    private void setupActionBar() {

    ViewGroup rootView = (ViewGroup)findViewById(R.id.action_bar_root); //id from appcompat

    if (rootView != null) {
        View view = getLayoutInflater().inflate(R.layout.app_bar_layout, rootView, false);
        rootView.addView(view, 0);

        Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }

    ActionBar actionBar = getSupportActionBar();

    //here assign the toolbar

    if (actionBar != null) {
        // Show the Up button in the action bar.
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}

So in my both tries neither toolbar nor actionbar works

Where am i going wrong?

Sagar
  • 23,903
  • 4
  • 62
  • 62
Geoff
  • 6,277
  • 23
  • 87
  • 197

0 Answers0