我是 Android 世界的新手。到目前为止,每个“OptionsMenu”都可以这样创建:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_list_view_controller, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.menu_settings:
startActivity(new Intent (ListViewControllerActivity.this, PreverencesActivity.class));
return true;
case R.id.menu_devsettings:
startActivity(new Intent (ListViewControllerActivity.this, DevPreferencesActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
但是现在,例如,新的 htc 没有硬件选项菜单按钮。当像我的源一样实现 OptionsMenu 时,显示屏内的菜单按钮将不会显示。 如何正确实现OptionsMenu,并且布局中不需要额外的按钮? 或者可以以某种方式激活显示屏内的这个按钮吗?
编辑: 我想我提供的信息有点少来解决这个问题,因为 android 不会在 API 16 Jelly Bean 中处理它。 再次如此。我已经实现了像上面这样的选项菜单。但现在“htc one”没有硬件选项菜单按钮,屏幕内选项菜单按钮不会显示。
这是我正在使用的布局 xml(可能是布局问题):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/img_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/txt_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#1e4870"
android:textColor="#ffffff"
android:layout_below="@+id/img_logo"/>
<ListView
android:id="@android:id/list"
android:layout_below="@+id/txt_title"
android:layout_above="@+id/img_bottom_bar"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
<ImageView
android:id="@+id/img_bottom_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/footer"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="@android:drawable/bottom_bar"
android:src="@android:drawable/bottom_bar" />
<RelativeLayout
android:id="@+id/footer"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<TextView
android:id="@+id/footer_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/footer_img_bs"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:id="@+id/footer_img_bs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
</RelativeLayout>
这里是 list 的一部分,我认为它可以解决这个问题:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
这个问题我也用谷歌搜索过很多次。但似乎我是这里唯一有这个问题的人。所以我必须有点愚蠢什么的。
免得我忘记:感谢 WebnetMobile.com 试图帮助我。可能是我(就像我之前说过的)太愚蠢而无法理解你的答案。
最佳答案
我已经解决了类似 this 的问题链接描述。您只需将“targetSdkVersion”从 16 更改为 10。
关于android 实现缺少硬件选项菜单按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12141501/