我想知道,是否有人可以帮助我解决以下问题:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:compat="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_summary"
android:icon="@drawable/ic_summary"
android:title="@string/action_summary"
compat:showAsAction="always" />
<item
android:id="@+id/action_filter"
android:icon="@drawable/ic_filter"
android:title="@string/action_filter"
compat:showAsAction="always" />
</menu>
行 compat:showAsAction="always"不起作用,它被忽略了。我在 fragment 中使用它,更具体地说,我使用 import android.app.Fragment;。结果我总是得到“三点”选项菜单。
我从来没有在这里发布过任何东西,到目前为止我总能找到一些解决方案。然而,这一次,我只找到了告诉我使用 compat:... 或 android:... 解决方案的解决方案,但它在我的情况下不起作用。
这是我的实际模块的 build.gradle(以防万一):
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com..."
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.+'
}
提前感谢您的帮助!
最佳答案
如果你正在使用 AppCompat 库,你最好不要使用 android.app.Fragment
而使用 android.support.v4.app.Fragment
。
(注意:您可以将 android.app.Fragment
与 AppCompat 库一起使用。但是,我遇到了一些因未使用 android.support.v4.app.Fragment
)
并且不要忘记,当您使用 android.support.v4.app.Fragment
时,您还必须使用 android.support.v4.app.FragmentManager
通过调用 getSupportFragmentManager()
作为 FragmentMangager
。
关于android - 兼容 :showAsAction ="always" does not work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32657682/