0

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!

this is my 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: enter image description here

Community
  • 1
  • 1
Mina Dahesh
  • 332
  • 8
  • 21

2 Answers2

1

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.

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!

[UPDATE]

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

Xcihnegn
  • 11,579
  • 10
  • 33
  • 33
  • thanks, but would you please say that how can i use style code?i create xml file in: values/styles.xml and write these code. but there is problem in "parent". how can i solve it? – Mina Dahesh Jan 03 '15 at 09:35
  • To use 'AppTheme', you need set 'android:theme="@style/AppTheme"' in your AndroidManifest file. And what's your problem with 'parent'? – Xcihnegn Jan 03 '15 at 12:43
  • have you import 'android-support-v7-appcompat' to your project? if not you have to do it also. – Xcihnegn Jan 03 '15 at 12:48
  • yes, i add AppTheme to Manifest.and import support v7 from this path : android-sdk-windows\extras\android\support\v7\appcompat\libs – Mina Dahesh Jan 03 '15 at 13:15
  • this theme is not recognized "Theme.AppCompat.Light".so i change it to "theme.holo.light." – Mina Dahesh Jan 03 '15 at 13:19
  • when i run the application, these errors are shown.(i will uplaod the photo) – Mina Dahesh Jan 03 '15 at 13:21
  • i download this file from github again and copy it into sdk, but "Theme.AppCompat.Light" is not recognize. – Mina Dahesh Jan 03 '15 at 14:17
  • this AppCompat jar file is in your Android SDK: android sdk\platforms\extras\android\support\v7\appcompat\libs – Xcihnegn Jan 03 '15 at 14:24
  • i do something, but really i don't know what, and these errors come now:1/android-apt-compiler: [Apk] F:Apk\res\values\styles.xml:3: error: Error retrieving parent for item: No resource found that matches the given name '@android:Theme.AppCompat'. 2/android-apt-compiler: [Apk] F:\Apk\res\values\styles.xml:9: error: Error retrieving parent for item: No resource found that matches the given name '@android:Widget.AppCompat.ActionBar'. – Mina Dahesh Jan 03 '15 at 15:59
  • i import jar file.but i do not know why this error is shown. – Mina Dahesh Jan 03 '15 at 16:01
  • Looks AppCompat not yet added to your project. Here is link for detatil to import support library: https://developer.android.com/tools/support-library/setup.html – Xcihnegn Jan 03 '15 at 18:56
  • excuse me, i couldn't solve it.but i upload my code in 4shared as below link. would you please say me, how can i solve it?thanks alot.http://www.4shared.com/zip/8YJOwBwMba/draft_theme.html – Mina Dahesh Jan 14 '15 at 15:43
  • now time i send you an email with "android question about AppCompat" and attach my code in it. – Mina Dahesh Jan 16 '15 at 15:54
  • The answer is little modified – Xcihnegn Jan 17 '15 at 10:23
1

In one of my projects, I used ActionBarSherlock.

  1. Download the abs here.

  2. Assuming you're using Eclipse IDE, right click your project, click properties, then android. At the bottom, in layout, add abs.

  3. Make sure abs and your project are in the same directory.

  4. Extend your classes to Sherlock naming. For example, instead of Activity, change it to Sherlock Activity. The main documentation of abs is found here.

  5. For easier usage of Sherlock, create util methods in changing the Sherlock names and modifying it.

Here is a sample code.

Hemanth
  • 2,717
  • 2
  • 21
  • 29
  • thanks, i do not know really, which AB is better and useful?the Ab i use, ABS?i can't compare between them. please guide me. – Mina Dahesh Jan 03 '15 at 08:53
  • i use InteliJ IDE, would you please guide me how can i use ABS in it? i could not find any best tutorial. – Mina Dahesh Jan 16 '15 at 15:57