Dumping AppCompat for API 21

2019-06-25 04:04发布

So I'm creating an app that is Lollipop 5.0 API 21 and up with zero interest in supporting older devices. Do I still need the appcompat library when using Material Design like UI elements & layouting (sidebar aka nav bar, ink, etc) ? When stripping it down I often encounter crashes when trying to move away from the AppCompat stuff. Changing activity types from the AppCompat one to the Normal one, I end up with problems regarding dependencies on layout types like the coordinator layout that aren't there.

I'm still new to android and this is very confusing, as my theme is currently in limbo somewhere between the appcompat theme & material design when I tried to change it from one of the template.

I've read that this is an android studio issue because it always uses appcompat regardless of your set dependencies & minimum API levels. Forcing you to manually override every implicit hidden appcompat call.

When trying to dump AppCompat, what changes to I need to do to make that happen ? Manifest, Activities, Menus, Layout, Styles ? It seems to touch all these things. If going exclusive without Appcompat, do you still need the v21 folders or will it grab the default ones ?

1条回答
够拽才男人
2楼-- · 2019-06-25 04:53

Do I still need the appcompat library when using Material Design like UI elements & layouting (sidebar aka nav bar, ink, etc) ?

If you are using classes out of the Design Support library, such as NavigationView, you generally need to use appcompat-v7 and AppCompatActivity. As of early May 2016, Google has not shipped a Design Support library analogue that works with Theme.Material. You may be able to find third-party library replacements for some of those widgets, and seasoned Android developers can sometimes "cross-port" these components to eliminate the appcompat-v7 dependencies.

I've read that this is an android studio issue because it always uses appcompat regardless of your set dependencies & minimum API levels. Forcing you to manually override every implicit hidden appcompat call.

The only place that Android Studio really cares about appcompat-v7 is in the new-activity wizards, which you do not have to use.

When trying to dump AppCompat, what changes to I need to do to make that happen ? Manifest, Activities, Menus, Layout, Styles ?

That is difficult to answer in the abstract. You would need to:

  • Stop using Design Support library widgets and containers

  • Stop inheriting from AppCompatActivity

  • Change your app: attributes in your menu resources to their android: equivalents

  • Change your theme to not use Theme.AppCompat

If going exclusive without Appcompat, do you still need the v21 folders or will it grab the default ones ?

-v21 resource directories are not tied to appcompat-v7. They will still be used, on API Level 21+ devices.

查看更多
登录 后发表回答