Android 中 API 8-10 中的 ActionBar [英] ActionBar in API 8-10 in Android

查看:30
本文介绍了Android 中 API 8-10 中的 ActionBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 API 级别 8-10 中使用 ActionBar.我搜索了解决方案并在下面找到了 2 个链接,但它们对我没有用.有人有同样的经历吗?谢谢!

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!

这是我的代码:

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

link1link2

当我运行项目时,会显示这些错误:

when i run the proje,these errors are shown:

推荐答案

ActionBar 在 Android 3.0(API 级别 11)中添加,但您可以通过使用 Spport 库在 ealier API 11 中使用它.要为 Action Bar 使用支持库,您的 Activity 应扩展 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>

希望对您有所帮助!

[更新]

要使用 AppCompat 主题,您必须从支持库 V7 中将 AppCompat 库导入到您的项目中:your-android-sdk\platforms\extras\android\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

这篇关于Android 中 API 8-10 中的 ActionBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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