gpt4 book ai didi

android - onOptionsItemSelected 未在 Activity 中调用

转载 作者:行者123 更新时间:2023-11-30 05:11:38 25 4
gpt4 key购买 nike

<分区>

这是我的问题。 onOptionsItemSelected() 未在点击抽屉时调用。所以这是我的代码,非常简单......

public class MainActivity extends AppCompatActivity {

private Toolbar toolbar;
private DrawerLayout drawer;
private ActionBarDrawerToggle toggle;
private RelativeLayout aboutUs, feedBack;
private View view;

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

view = findViewById(R.id.mainView);
aboutUs = (RelativeLayout) findViewById(R.id.list4);
feedBack = (RelativeLayout) findViewById(R.id.list5);

initToolbar();
drawerInit();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
if (drawer.isDrawerOpen(Gravity.LEFT)) {
drawer.closeDrawer(Gravity.LEFT);
} else {
drawer.openDrawer(Gravity.LEFT);
}
}
return super.onOptionsItemSelected(item);
}

public void initToolbar() {
toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}

public void drawerInit() {
drawer = (DrawerLayout) findViewById(R.id.drawer);

toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.drawer_open, R.string.drawer_close) {

@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
float moveFactor = (drawerView.getWidth() * slideOffset);
view.setTranslationX(moveFactor);
}

@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
};

drawer.addDrawerListener(toggle);
toggle.setDrawerIndicatorEnabled(true);
toggle.syncState();
}

@Override
protected void onDestroy() {
super.onDestroy();
}

我在 optionsItemSelected 回调中设置了断点,但这对抽屉点击不起作用。

但是抽屉打开了。那么问题出在哪里,我该如何解决呢?谢谢回答......................................

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com