“setSupportActionBar(toolbar)” inside FragmentActi

2020-05-21 07:32发布

How do I access setSupportActionBar(Toolbar toolbar) inside FragmentActivity? I can't access it inside FragmentActivity

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

9条回答
别忘想泡老子
2楼-- · 2020-05-21 08:16

Instead of using setSupportActionBar use setActionBar Eg:

android.widget.Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);    
setActionBar(toolbar);
查看更多
Lonely孤独者°
3楼-- · 2020-05-21 08:21

Use ActionBarActivity from support library, ActionBarActivity extends FragmentActivity, So that you can get SupportFragmentManager and set toolbar as actionbar

Ex:

public class MainActivity extends ActionBarActivity
{

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

 FragmentManager manager=this.getSupportFragmentManager();
}
查看更多
Juvenile、少年°
4楼-- · 2020-05-21 08:23

With the latest version of the support library you should make your Activity extend AppCompatActivity as ActionBarActivity has been deprecated.

It provides the same functionality as your ActionBarActivity previously did. You shouldn't need to make any further changes.

查看更多
登录 后发表回答