平板电脑中的 Android 操作栏菜单

标签 android

在我创建的新应用程序中,我获得了用于创建菜单的自动生成代码:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

然后我在 menu.xml 中添加了项目

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

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>
    <item android:id="@+id/item1"></item>

</menu>

但是没有菜单按钮,我是不是错过了什么?

最佳答案

编辑:

在您的菜单定义中,您输入:

android:showAsAction="never"

将其更改为:

android:showAsAction="always"

检查此示例,包括菜单图标:

<item 
    android:id="@+id/menu_calendar"
    android:title="@string/calendar"
    android:icon="@drawable/ic_menu_calendar_holo_light"        
    android:showAsAction="always|withText" />

always 表示按钮将始终显示。如果是应该作为选项出现在菜单中但并非一直显示的菜单(例如设置),您可以将其替换为 ifRoom

withtext 表示如果有足够的空间,菜单的标题将显示在图标旁边。

有关所有这些选项的详细信息可用 here .

对于其余部分,您需要在 onCreate() 函数中创建并显示 ActionBar:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 

    //you might need this line if you are not using the Holo theme
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

    setContentView(R.layout.main_activity);

    ActionBar actionBar = getActionBar();
    actionBar.show();

(...)

关于平板电脑中的 Android 操作栏菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16685296/

相关文章:

php - 使用 php 通过 android volley 发送图像

java - 如何使用多个参数调用 HTTP POST 请求?

具有数据绑定(bind)的 Android 架构组件

java - 从 Android 中的 Asynctask 返回 boolean 值

Android 静态布局字体大小

android - 复杂的 SOAP 请求

android - javacv:应用程序以 opencv_contrib.createLBPHFaceRecognizer 终止

android - 如何制作这样的形状?

android - 无法使用WebView播放视频

android - 如何使用 json 编码的正文进行 httpPost 调用?