汉堡包不起作用



我设法创建了一个抽屉并有汉堡包标志,但汉堡包在点击时不起作用。另外,我如何更改代码,以便我的应用程序具有透明的通知栏,以便颜色相同(或者最好更深一点(,并且可以看到在状态栏中打开的应用程序抽屉。像这样的东西:透明状态栏

第一活动.java:

public class FirstActivity extends AppCompatActivity {
DrawerLayout mDrawer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_me_clicked);
Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);    //removes the package name from toolbar
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//            Window w = getWindow(); // in Activity's onCreate() for instance          //Integration of app into status bar
//            w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//        }
// These lines are needed to display the top-left hamburger button
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

// Make the hamburger button work
mDrawer = (DrawerLayout) findViewById(R.id.DL);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDrawer,R.string.app_name,R.string.app_name){
@Override
public void onDrawerClosed(View drawerView) {
}
@Override
public void onDrawerOpened(View drawerView) {
}
};
mDrawer.addDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
// toasts the message when ListView item is clicked
ListView mDrawerListView = (ListView) findViewById(R.id.left_drawer);
mDrawerListView.setOnItemClickListener(new ListView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String drawerstring = ("Menu Item at position " + position + " clicked.");
mDrawer.closeDrawer(GravityCompat.START);
Toast.makeText(getApplicationContext(),drawerstring,Toast.LENGTH_SHORT).show();
}
});
}

您必须覆盖 onOptionsItemSelected 并处理主项目以打开抽屉。 它不是为你做的,因为Android不知道你在用那个按钮做什么(家? 返回? 汉堡? 别的什么? ActionDrawerToggle 知道如何处理它,如果你只想委派它。

相关内容

  • 没有找到相关文章

最新更新