What is the alternative to getActionBar()?

后端 未结 2 1776
小蘑菇
小蘑菇 2020-12-21 22:49

When I try to use getActionBar() it says it is deprecated, so that means by going forward we are not allowed to use getActionBar().

Which

2条回答
  •  清歌不尽
    2020-12-21 23:28

    The reason you should create this, because Fragment Tabs using ActionBar is now deprecated. This is new way to create your actionbar with Material Design. to use this you need to add dependencies in your build.gradle file.

    compile 'com.android.support:appcompat-v7:21.0.0'
    

    create toolbar app_bar.xml file, you can give the name you want.

    
    
    

    Make sure, you selected theme in styles.xml with

    "Theme.AppCompat.NoActionBar"
    

    after that, you need to initialize this toolbar in your mainActivity.xml layout file, for that include this,

     
    

    then in the MainActivity, you need to make instance of Toolbar toolbar. then, after setContentView() add following with your

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

提交回复
热议问题