You need to use Theme.AppCompat (or child) theme with this action on Android

I have this in action:

public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener{ private Toolbar mToolbar; private FragmentDrawer drawerFragment; private RecyclerView recyclerView; private IsAdapter isAdapter; private List<Is> isList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); recyclerView = (RecyclerView) findViewById(R.id.recycler_view); isList = new ArrayList<>(); isAdapter = new IsAdapter(this, isList); RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(this, 1); recyclerView.setLayoutManager(mLayoutManager); recyclerView.addItemDecoration(new GridSpacingItemDecoration(2, dpToPx(10), true)); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setAdapter(isAdapter); drawerFragment = (FragmentDrawer) getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer); drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar); drawerFragment.setDrawerListener(this); // display the first navigation drawer view on app launch displayView(0); } 

I use my own theme (which is material), it works well, then I made some changes to the code, now I get this error. How can i fix this? Thanks in advance.

My manifest file I have is: android:theme="@style/MyMaterialTheme">

I googled, solutions say change AppCompatActivity to Activity or FragmentActivity . When I do this, I get an error in these lines:

 setSupportActionBar(mToolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); 

Here are my styles.xml:

 <resources> <style name="MyMaterialTheme" parent="MyMaterialTheme.Base"> </style> <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="windowNoTitle">true</item> <item name="windowActionBar">false</item> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> </resources> 
-3
source share
4 answers

Change it

 <style name="MyMaterialTheme" parent="MyMaterialTheme.Base"> </style> <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="windowNoTitle">true</item> <item name="windowActionBar">false</item> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> 

to that

 <style name="MyMaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="windowNoTitle">true</item> <item name="windowActionBar">false</item> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> 

Full code:

 <resources> <style name="MyMaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="windowNoTitle">true</item> <item name="windowActionBar">false</item> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> </resources> 

and then clean project and rebuild it.

+1
source

All you have to do is add android: theme = "@ style / Theme.AppCompat.Light" to your application tag in the AndroidManifest.xml file.

+2
source

If I understand correctly, you have already defined the MyMaterialTheme style in values/styles.xml . Your main topic topic is extended by one of Theme.AppCompat.{Light,Dark}.NoActionBar ? For instance:

 <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"> 
+1
source

change these two lines

 setSupportActionBar(mToolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); 

Use these

 setActionBar(mToolbar); getActionBar().setDisplayShowHomeEnabled(true); 
+1
source

Source: https://habr.com/ru/post/1011939/


All Articles