onOptionsItemsSelected 无法覆盖且未使用?

onOptionsItemsSelected cannot be overridden and is unused?

所以我已经在互联网上搜索了几个小时,但找不到解决方案。这段代码似乎有两个问题,第一个是 onOptionsItemsSelected 的 @Override(方法不覆盖它的超类的方法),第二个是 onOptionsItemsSelected 本身。 onOptionsItemsSelected 告诉我该方法从未使用过,我认为这可能是我遇到 @Override 问题的原因。我只是不确定我忽略的是什么。我在下面提供了 java 代码,如果需要 xml 代码,请告诉我,我会尽快 post 。提前致谢。

package com.example.main_navigation;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

public class WalletActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wallet);
    }

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.actionbar_menu, menu);
        return true;
    }
    @Override  ///First issue is here and 2nd issue is right below this line
    protected boolean onOptionsItemsSelected(final MenuItem item) {

        final int id = item.getItemId();
        if (id == R.id.action_custom_button) {
            startActivity(new Intent(getApplicationContext(), NavigationActivity.class));
            overridePendingTransition(0, 0);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}

它是 onOptionsItemSelected - 项目,而不是项目。

对于第一期:将方法范围从 protected 更改为 public

对于第二期:onOptionsItemsSelected tells me the method is never used这是AndroidStudio的警告,因为没有调用这个方法所以没用

尝试使用以下源代码代替 onOptionsItemsSelected class。

@Override  ///First issue is here and 2nd issue is right below this line
protected boolean onOptionsItemsSelected(final MenuItem item) {

    final int id = item.getItemId();
    if (id == R.id.action_custom_button) {
        startActivity(new Intent(getApplicationContext(), NavigationActivity.class));
        overridePendingTransition(0, 0);
        return true;
    }
    return super.onOptionsItemSelected(item);
}