Android:在其他提示都不起作用时将项目添加到操作栏
Android: Adding items to Action Bar when no other tips work
基本上,我正在尝试向操作栏添加一个项目,但它不起作用。我查阅了很多主题,但 none 的提示确实很有帮助。我是 运行 Samsung Galaxy Note II 上的应用程序。
这是 activity 的相关部分:
public class AddItem extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_add_item, menu);
return super.onCreateOptionsMenu(menu);
}
这是菜单 xml 文件:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_edit"
android:icon="@drawable/ic_action_edit"
android:title="Edit"
app:showAsAction="always" />
这是 Gradle 构建文件片段:
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "***"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
样式如下 xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/abar</item>
</style>
基本上就是这样。无论我做什么,"Edit" 按钮都会溢出(我必须按 phone 的菜单按钮才能弹出)。如何让它出现在我的操作栏上?
这是因为您的 phone 有一个硬件菜单按钮,它可以在任何其他设备上按预期工作。 Here 你可以找到一些关于如何作弊的信息。
基本上,我正在尝试向操作栏添加一个项目,但它不起作用。我查阅了很多主题,但 none 的提示确实很有帮助。我是 运行 Samsung Galaxy Note II 上的应用程序。
这是 activity 的相关部分:
public class AddItem extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_add_item, menu);
return super.onCreateOptionsMenu(menu);
}
这是菜单 xml 文件:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_edit"
android:icon="@drawable/ic_action_edit"
android:title="Edit"
app:showAsAction="always" />
这是 Gradle 构建文件片段:
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "***"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
样式如下 xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/abar</item>
</style>
基本上就是这样。无论我做什么,"Edit" 按钮都会溢出(我必须按 phone 的菜单按钮才能弹出)。如何让它出现在我的操作栏上?
这是因为您的 phone 有一个硬件菜单按钮,它可以在任何其他设备上按预期工作。 Here 你可以找到一些关于如何作弊的信息。