扩展活动或ActionBarActivity [英] Extending Activity or ActionBarActivity

查看:153
本文介绍了扩展活动或ActionBarActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个应用程序,其中包括为Android棒棒糖和支持更早版本。

根据保持兼容性我计划用ActionBarActivity与AppCompact非文档棒棒糖设备和FragmentActivity与材料棒棒糖设备。

我创建了两个不同的价值的文件夹。

现在的问题是,我应该如何延长我的活动类

  MyActivity延伸活动

  MyActivity延伸ActionBarActivity

如果我使用的活动。它崩溃的早期Android版本,并说我补充ActionBarActivity和反之亦然为发生棒棒糖

编辑------

值-21

 <样式名称=AppTheme父=机器人:Theme.Material.Light>

 <样式名称=AppTheme父=Theme.AppCompat.Light>


解决方案

您,如果您要使用的API在ActionBar延长ActionBarActivity为API> = 7退房的 http://developer.android.com/guide/topics/ui/actionbar.html

此外,它可以是混乱的来源,但是当你使用 ActionBarActivity
你的主题必须是 Theme.AppCompact 后裔之一的孩子,如

 <样式名称=MyTheme的父=Theme.AppCompact>
    <项目名称=机器人:colorPrimary> @彩色/ accent_1< /项目>
    <项目名称=机器人:colorPrimaryDark> @彩色/ accent_dark< /项目>
    <项目名称=机器人:colorAccent>#F00< /项目>    <项目名称=colorPrimary> @彩色/ accent_1< /项目>
    <项目名称=colorPrimaryDark> @彩色/ accent_dark< /项目>
    <项目名称=colorAccent>#F00< /项目>< /风格>

非prefixed 的android:提供您谈到您希望为用户提供材料的主题兼容性< API 21(棒棒堂)

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">

解决方案

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)

这篇关于扩展活动或ActionBarActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆