I'll be brief. I have activity settings. AppCompat.Light application theme.

However, when I launch the settings activity, it is shown without an ActionBar .

What is the problem? I need an ActionBar displayed.

Manifest file:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.dimantik.myapplication"> > <application android:allowBackup="true" android:icon="@mipmap/app_icon" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".TopActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".CreateTaskActivityFirst" android:label="Новая задача" android:parentActivityName=".TopActivity" android:windowSoftInputMode="adjustPan" /> <activity android:name=".ShowTaskActivity" android:parentActivityName=".TopActivity" /> <activity android:name=".EditTaskActivity" android:windowSoftInputMode="adjustPan" /> <activity android:name=".SettingsActivity" android:parentActivityName=".TopActivity" android:label="Настройки"/> <service android:name=".MyIntentService" android:exported="false"> </service> </application> </manifest> 

SettingsActivity code:

 package com.example.dimantik.myapplication; import android.os.Bundle; import android.os.PersistableBundle; import android.preference.PreferenceActivity; import android.support.v7.app.AppCompatActivity; /** * Created by Dimantik on 02.11.2016. */ public class SettingsActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); } } 

    1 answer 1

    The problem is that PreferenceActivity does not have an ActionBar .

    And in general, the PreferenceActivity.addPreferencesFromResource(...) method is deprecated , therefore, it is better not to use it .

    If you need ActionBar , then I will offer a solution based on the use of PreferenceFragment :

    Create a SettingsFragment class:

     public class SettingsFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); } } 

    And change your SettingsActivity :

     public class SettingsActivity extends AppCompatActivity { @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit(); } } 

    As a result, get an idea with the desired ActionBar :

    enter image description here