我有一个叫做BaseActivity
的主类,它有一个方法
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.main, menu);
return true;
}
现在我像这样扩展此类...
public class MainActivity extends BaseActivity {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
Log.d("Its called", "Kevin");
menuInflater.inflate(R.menu.othermenu, menu);
}
}
如果是
boolean
或void
,我将如何在此处覆盖此方法。更新:
public class FragmentClass extends android.support.v4.app.Fragment {
// How would i over-ride the onCreateOptionsMenu() here of BaseActivity.
}
最佳答案
任何覆盖方法都必须具有与其覆盖的方法相同的签名。别忘了叫super,就像这样:
public class MainActivity extends BaseActivity {
@Override
public boolean onCreateOptionsMenu( Menu menu ) {
if( super.onCreateOptionsMenu( menu ) ) {
Log.d("Its called", "Kevin");
getSupportMenuInflater().inflate(R.menu.othermenu, menu);
return true;
} else {
return false;
}
}
}
关于java - 从baseActivity类重写onCreateOptionsMenu,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15660934/