2016-01-04 96 views
0

我是android開發新手,正在開發一個溢出菜單。爲此,我必須更改我的應用程序的主題,以便包含溢出菜單的操作欄可見。Android Studio渲染問題:缺失頂欄

但是android studio沒有使用操作欄來渲染任何主題。

我搜索了互聯網的解決方案,發現一個在stackoverflow上說我不得不更新我的res/values/styles.xml文件。我更新了名爲AppTheme的標籤,但它並未解決我的問題。

我試圖使緩存無效並重新啓動,但仍未解決。我也試圖清理這個項目並重建它。沒有工作。

我附上錯誤的截圖。 請幫助。

enter image description here

這裏是我的styles.xml文件:

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 

    <style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

</resources> 

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.naveenjain.test3"> 

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

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

</manifest> 
+0

添加styles.xml –

+0

添加您的AndroidManifest.xml – piotrek1543

+0

問題就解決了,當我選擇空活動,而不是空活動,但隨後我無法創建溢出菜單。 請幫忙!! – Ayusch

回答

0

按照問題:You need to use a Theme.AppCompat theme (or descendant) with this activity 你需要遵循以下步驟:

您遇到此問題的原因是因爲您嘗試應用對話主題的活動是 正在擴展ActionBarActivity 需要應用AppCompat主題。

將Java繼承性從ActionBarActivity更改爲Activity和 將對話主題保留在清單中,照原樣。

檢查更多的解決方案

上面的鏈接希望它能幫助

+0

雖然我的主要活動是從AppCompatActivity擴展,但是當我將其更改爲從Activity延伸時,它仍然沒有解決問題。 我是android開發的新手,所以如果列出解決方案的步驟會很有幫助。 謝謝 – Ayusch

+0

添加'build.gradle'文件(您可能有依賴關係的問題),如果可能的話Java類 – piotrek1543