0

I am following udacity to course to learn android developement. when I run the app on emulator, action bar is not shown.

I have another activity which is triggered by the main activity. If I do not add following line in android_manifest file then when clicking on listview in main activity gives me following error

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

So I googled this error and I got that App-Compat should be used. So I added this following line in android_manifest file

<application
....
....
  android:theme="@style/Theme.AppCompat"
>.....</application>

So after adding this line I get following screen which has no action bar. ScreenShot

When I remove the line in android:theme="@style/Theme.AppCompat manifest file, I get Action bar but after clicking the list view gives me that error

EDIT

This is my styles.xml file

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

EDIT

My manifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.suraj.sunshine">

  <uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


    <activity
        android:name=".DetailedActivity"
        android:label="@string/title_activity_detailed"
        android:parentActivityName=".MainActivity"
        >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.suraj.sunshine.MainActivity" />
    </activity>

    <activity
        android:name=".SettingsActivity"
        android:label="@string/title_activity_detailed"
        android:parentActivityName=".MainActivity"
        >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.suraj.sunshine.MainActivity" />
    </activity>
 </application>

</manifest>
Jongware
  • 22,200
  • 8
  • 54
  • 100
Suraj Palwe
  • 2,080
  • 3
  • 26
  • 42

2 Answers2

0

Try this code in your Manifest.

//use android:theme="@style/AppTheme" Instead of android:theme="@style/Theme.AppCompat"

<application
    ....
    ....
      android:theme="@style/AppTheme"
    >.....</application>
Venkatesh Selvam
  • 1,382
  • 2
  • 15
  • 28
0

Try this in your style.xml:

 <style name="AppTheme" parent="AppBaseTheme">

And in manifest:

<application android:theme ="@style/AppTheme"> 

</application>

Hope it helps.

Jiri Tousek
  • 12,211
  • 5
  • 29
  • 43
Pooja
  • 31
  • 5