Android getActionBar vs getSupportActionBar?

前端 未结 2 552
名媛妹妹
名媛妹妹 2020-12-16 03:22

Here is my code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){

    //android.support.v7.app.ActionBar actionBar = getSupportActionBar();
           


        
相关标签:
2条回答
  • 2020-12-16 04:01

    If you are extending AppCompatActivity then you are providing backward support for older Android versions and for that you have to use getSupportActionBar().

    If you are importing android.app.ActionBar then you have to use getActionBar() and if you are importing android.support.v7.app.ActionBar then you have to use getSupportActionBar().

    Note: By using android.support.v7.app.ActionBar, you can provide backward support for older Android versions.

    0 讨论(0)
  • 2020-12-16 04:02

    If you are using AppCompat you always have to call getSupportActionBar() no matter which Android Version your App is running.

    Which Android versions do you target?

    I would advise you to use the new Toolbar instead of ActionBar, because it's way more flexible to use.

    0 讨论(0)
提交回复
热议问题