Android studio - 操作栏上的图标总是列在溢出菜单中,为什么?

时间:2017-09-18 17:20:40

标签: android mobile android-actionbar icons

我那个时刻的应用程序有3个按钮,允许开关LED和通过蓝牙从湿度传感器读取数据(每个发送另一个命令到arduino,例如'0' - LED关闭,'1' - LED开,'2 ' - 阅读数据。)

今天我想添加发送任何消息给arduino,所以我将EditTextBox插入到我的布局中,我决定从这个EditTextBox向Arduino发送消息的按钮将位于带有此图标send icon的操作栏上

菜单 - > main.xml中

`<!-- language: lang-xml -->
     <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
     <item
         android:id="@+id/action_send"
         android:icon="@drawable/ic_send_black_48dp"
         android:title="@string/action_send" // this string is empty ' '
         android:orderInCategory="1"
         app:showAsAction="always" />

        <item
            android:id="@+id/action_settings"
            android:orderInCategory="2"
            android:title="@string/action_settings" 
            app:showAsAction="never" />
    </menu>`

MainActivity.java

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // COMPLETED (9) Within onCreateOptionsMenu, use getMenuInflater().inflate to inflate the menu
        getMenuInflater().inflate(R.menu.main, menu);
        // COMPLETED (10) Return true to display your menu
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_settings:
            Context context = MainActivity.this;
            String textToShow = "...";
            Toast.makeText(context, textToShow, Toast.LENGTH_SHORT).show();
            return true;


        case R.id.action_send:
            mConnectedThread.write(txtBluetooth.getText().toString());
            return true;

        default:
            // If we got here, the user's action was not recognized.
            // Invoke the superclass to handle it.
            return super.onOptionsItemSelected(item);
        }
    }

你怎么看,我设置了app:showAsAction="always" />,尽管操作栏上缺少这个发送图标并被发送到溢出菜单,如图所示:app

那么,我如何防止这种情况并使溢出菜单中的操作栏上显示发送图标?

0 个答案:

没有答案