Difference between support.v7.widgets and android.

2019-03-20 03:09发布

问题:

I am creating a new application and will have to deal with ActionBar. I know that I have to extend the AppCompatActivity because the ActionBarActivity is deprecated, however I still do not understand why I have to use the support.v7.widget Toolbar rather than the android.widget Toolbar even though I am using the latest API ?

Thank you

EDIT1:

I understand now that the support.v7.widgets are there to enable devices with old APIs to comprehend what are the new functionalities added in the newer versions and mimic them in their own way. Is that correct ?

If that is correct and I do not want to have any sort of backwards compatibility does this mean I can move forward and use the android.widget Toolbar ?

Also using the android.widget Fragment unfortunately I can not add it to a ViewPager. Why is that ? Why does it force me to use an older version which has been extended to mimic the behaviour of the new implementation of the component ?

I think I just getting lost in all of those "support" libraries. Can someone briefly ( or not ) explain all that - why are there things in the support libraries that are not included or updated in the newer versions of the API ?

Thank you

回答1:

First of all you are asking Good Question, Android will add advanced features continuously in different API levels but those features are available from which level of API they are added

For Example: Consider android fragment functionality was added in API level 11 that means it will work for API level 11 and above but your application need for API level 10 devices also at that time it wont be work. For this reason android develop support library for cover a wide range of Android devices (support for low level API) to work those functionality.

Android always recommend developers to use support library for development for more information check here



回答2:

  • Support.V7.widgets and widgets.android both are different libraries.
  • support.v7.widgets uses design library.
  • toolbar actually not an actionbar we are manually implementing a ActionBar with support library.
  • And there are lot more new inbuilt properties are included like observableScrollActivity and More material designs...,

  • Why we aren't using default actionbar?

    Because ActionBarActivity is depricated. Comparing old actionbar with our latest sdk actionbar it gives good look.

    .setSupportActionBar(toolbar);

After Setting support to the toolbar gives actionbar properties to the toolbar like we can hide it by getSupportActionBar().hide();