动作条在8-10 API在Android中动作、Android、API

2023-09-12 21:50:47 作者:从头再来

我想用动作条在API级别8-10。我搜索的解决方案,并找出2链接波纹管,但它们并不是me.is还有谁的人有同样的经历有用吗?谢谢!

i want to use ActionBar in API level 8-10. i search solutions and find out 2 links bellow, but they are not useful for me.is there someone who has the same experience?Thanks!

这是我的code:

 ActionBar actionBar =getActionBar();
    assert actionBar != null;
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#e32238")));

link1 link2

当我运行的幻灯,这些错误显示:

when i run the proje,these errors are shown:

推荐答案

动作条中加入的Andr​​oid 3.0(API级别11),但您可以通过使用Spport库使用更早期的API 11。要使用支持库行动吧,你应该活动来延长ActionBarActivity。

ActionBar added in Android 3.0 (API level 11), but you can use it in ealier API 11 by using Spport Library. To use support library for Action Bar, your activity should extends ActionBarActivity.

要定制你的动作条的颜色,你可以在styles.xml文件中设置动作条的风格,是这样的:

To custom your action bar color, you can set actionbar style in styles.xml file, something like:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light">                
    <item name="actionBarStyle">@style/MyActionBar</item>

</style>


<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <!-- for before API 11 -->
    <item name="background">@color/your_color</item>
    <!-- for after API 11 -->
    <item name="android:background">@color/bg_blue</item>
</style>

希望这有助于!

Hope this help!

[更新]

要使用AppCompat的主题,你必须AppCompat库的支持库V7导入到项目中:您-Android的SDK \平台\演员\机器人\ SUPPORT \ V7 \ appcompat

To use AppCompat theme, you have to import AppCompat library to your project from support library V7: your-android-sdk\platforms\extras\android\support\v7\appcompat