0

I am creating ActionBar using android-support-v7-appcompat. In action bar I have up navigation from logo enabled and its working fine on device with API level 17. But when I run my app on API level 10 device its not working. Please help me. Thanks in advance.

Using following code in activity-

private ActionBar ab;
ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);

In Manifest file-

<activity
 android:name=".History"
 android:screenOrientation="portrait"
 android:theme="@style/Theme.Styled"
 android:parentActivityName=".MainActivity">
John R
  • 2,078
  • 8
  • 35
  • 58

1 Answers1

3

ActionBar is not supported for below API 11 level.Thats why you are getting error.Read this documentation.

To make your code work in lower version, you have to use android-support-v7-appcompat instead of ActionBar.Read the below blog about how to migrate from ActionBar to android-support-v7-appcompat.

http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html

EDIT : you can download and setup the support library as mentioned here

Below is my explanation based on your updated code,

-To enable up navigation in beginning in Android 4.1 (API level 16), you can declare the logical parent of each activity by specifying the android:parentActivityName attribute in the element.

-If your app supports Android 4.0 and lower, include the Support Library with your app and add a <meta-data> element inside the . Then specify the parent activity as the value for android.support.PARENT_ACTIVITY, matching the android:parentActivityName attribute like below example,

 <activity
        android:name="com.example.myfirstapp.DisplayMessageActivity"
        android:label="@string/title_activity_display_message"
        android:parentActivityName="com.example.myfirstapp.MainActivity" >
        <!-- Parent activity meta-data to support 4.0 and lower -->
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.myfirstapp.MainActivity" />
    </activity>

For more info read http://developer.android.com/training/implementing-navigation/ancestral.html Hope it helps you.

Spring Breaker
  • 8,233
  • 3
  • 36
  • 60
  • I am already using android-support-v7-appcompat. sorry I forget to write in question. – John R Feb 05 '14 at 06:59
  • @JohnR: In that case, update your question along with full logcat error. – Spring Breaker Feb 05 '14 at 07:00
  • Everything working fine. But when I run my app on device with API level 10. Then back from logo icon in action bar not work. – John R Feb 05 '14 at 07:02
  • can you see this link for overflow icon please http://stackoverflow.com/questions/21569347/navigating-up-and-overflow-icon-in-action-bar – John R Feb 05 '14 at 07:49