Alexei
Alexei

Reputation: 15674

Can't set androidx.appcompat.widget.Toolbar to androidx.fragment.app.FragmentActivity

In my android project:

import androidx.fragment.app.FragmentActivity;
import androidx.appcompat.widget.Toolbar;

public class MainFragmentActivity extends FragmentActivity {

Toolbar mToolbar = (Toolbar) findViewById(R.id.toolBar);
setSupportActionBar(mToolbar);
}

I wanto to set toolbar in androidx.fragment.app.FragmentActivity

but in line:

setSupportActionBar(mToolbar);

I get compile error:

Cannot resolve method 'setSupportActionBar(androidx.appcompat.widget.Toolbar)'

I can't extend MainFragmentActivity from AppCompatActivity

I have no source code of MainFragmentActivity

Upvotes: 2

Views: 530

Answers (1)

Jasurbek
Jasurbek

Reputation: 2966

FragmentActivity does not have setSupportActionBar method

if you really need actionBar then try to extend AppCompactActivity

like following

public class MainFragmentActivity extends AppCompatActivity {

Toolbar mToolbar = (Toolbar) findViewById(R.id.toolBar);
setSupportActionBar(mToolbar);
}

Upvotes: 1

Related Questions