2016-01-04 98 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