Extending Activity or ActionBarActivity

守給你的承諾、 提交于 2020-02-02 11:27:36

问题


I'm creating an app which includes support for Android Lolipop and earlier versions.

Based on Maintaining compatibility documentation i planned to use ActionBarActivity with AppCompact for non Lolipop devices and FragmentActivity with material for Lolipop devices.

I created two different value folders.

Now the problem is how should i extend my Activity class with

MyActivity extends Activity 

or

MyActivity extends ActionBarActivity

If i use Activity. It crashes on earlier android version and saying me to add ActionBarActivity and the vice versa happens for lolipop

EDIT ------

values-21

<style name="AppTheme" parent="android:Theme.Material.Light">

values

<style name="AppTheme" parent="Theme.AppCompat.Light">

回答1:


You extend ActionBarActivity if you'll be using the ActionBar on api s lower then 11 for support for api >=7 check out http://developer.android.com/guide/topics/ui/actionbar.html

Also it can be a source of confusion but when you use ActionBarActivity your theme must be a child of one of Theme.AppCompact descendents such as

 <style name="MyTheme" parent="Theme.AppCompact">
    <item name="android:colorPrimary">@color/accent_1</item>
    <item name="android:colorPrimaryDark">@color/accent_dark</item>
    <item name="android:colorAccent">#f00</item>

    <item name="colorPrimary">@color/accent_1</item>
    <item name="colorPrimaryDark">@color/accent_dark</item>
    <item name="colorAccent">#f00</item>

</style>

The non prefixed android:provide the Material theme compatibility that you talked you want for users of < API 21 (Lollipop)




回答2:


Extend ActionBarActivity and use Theme.AppCompat - so your style theme will be this only values-21

<style name="AppTheme" parent="Theme.AppCompat">

values

<style name="AppTheme" parent="Theme.AppCompat">

try this and let me know if it works

NOTE1: ive not tried it, and im conjuring from a wide range of thoughts

ps; yes ive read the documentation..



来源:https://stackoverflow.com/questions/26449454/extending-activity-or-actionbaractivity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!