选项未显示在操作栏中

时间:2018-04-06 07:32:16

标签: android android-actionbar

我正在尝试在主页的操作栏中显示“添加审核”,“同步”和“注销”选项。但是在运行应用程序后,它们都不会显示出来。

它的XML内容是:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <app:item
        android:id="@+id/action_add"
        android:layout_width="wrap_content"
        android:text="@string/create_audit"
        android:title= "@string/add_audit"
        app:showAsAction="always" />
    <app:item
        android:id="@+id/action_sync"
        android:icon="@drawable/sync_outline"
        android:title="@string/action_sync"
        app:showAsAction="always" />
    <app:item
        android:id="@+id/action_logout"
        android:icon="@drawable/logout_button1"
        android:title="@string/action_logout"
        app:showAsAction="withText|collapseActionView|ifRoom" />
</menu>

这在旧项目中完美运行。在我将旧项目的内容移动到新项目后,它停止了工作。 我尝试降级compileSDKversion和targetSDKversion,但它不起作用。 我查看了代码,一切似乎都很好。

我的应用级关注内容是:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.sparsh.newcsraudit"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath false
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation project(':squarecamera')
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'com.jakewharton:butterknife:7.0.1'
    implementation 'com.amazonaws:aws-android-sdk-s3:2.6.16'
    implementation 'se.emilsjolander:stickylistheaders:2.7.0'
    implementation 'com.squareup.picasso:picasso:2.4.0'
    implementation 'io.paperdb:paperdb:0.9'
    implementation 'com.fabiendevos:nanotasks:1.1.0'
    implementation 'com.flipboard:bottomsheet-core:1.5.0'
    implementation 'com.flipboard:bottomsheet-commons:1.5.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.squareup.okhttp:okhttp:2.7.5'
    implementation 'com.squareup.okhttp:okhttp-urlconnection:1.6.0'
    implementation 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    implementation 'com.squareup.retrofit:converter-jackson:2.0.0-beta2'
    implementation 'com.getbase:floatingactionbutton:1.10.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    androidTestImplementation 'com.android.support.constraint:constraint-layout:1.0.2'
}

styles.xml包含:

<resources>

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

</resources>

这是通货膨胀的代码:

@Override public boolean onCreateOptionsMenu(Menu menu)
 {
 // Inflate the menu items for use in the action bar
 MenuInflater inflater = getMenuInflater();   
 inflater.inflate(R.menu.main_activity_actions, menu); 
return super.onCreateOptionsMenu(menu);
 }

我在StackOverflow上看到了类似的问题,但没有得到解决方案。 请帮我解决这个问题。提前谢谢!

0 个答案:

没有答案