-2

I have this in Activity :

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'm using my own theme (which is material), It was working well, then I made some changes in the code, now I get this error. How can I fix this? Thanks in advance.

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

I googled, the solutions say change AppCompatActivity to Activity or FragmentActivity. When I do that, I get error at these lines :

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

Here is 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>
jason
  • 6,962
  • 36
  • 117
  • 198

4 Answers4

2

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

Puneet
  • 108
  • 3
1

If I understood correctly, You have already defined a style MyMaterialTheme in values/styles.xml. Does Your most base theme extends one of the Theme.AppCompat.{Light,Dark}.NoActionBar? For example:

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
R. Zagórski
  • 20,020
  • 5
  • 65
  • 90
1

change these two lines

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

Use these

setActionBar(mToolbar);
getActionBar().setDisplayShowHomeEnabled(true); 
Mithilesh Izardar
  • 2,117
  • 1
  • 13
  • 24
1

Change this

<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 this

<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 the project and rebuild it.

Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95