gpt4 book ai didi

android - 通过操作栏标题切换抽屉导航

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:50:52 24 4
gpt4 key购买 nike

我试图让用户通过点击操作栏标题来打开/关闭我的应用程序中的抽屉导航(这是当前 Android Gmail 应用程序的设置方式)。目前,用户可以通过点击应用程序/抽屉图标或通过左右滑动将其滑入来切换抽屉。但是,操作栏标题本身是不可点击的。根据developer docs , 当我们使用 NAVIGATION_MODE_STANDARD 但出于某种原因,我无法让标题以这种方式运行。

我相信 Navigation Drawer 本身没问题,但这是我设置 Action Bar 的方式:

private void configureActionBar(CharSequence mTitle) {

ActionBar actionBar = getActionBar();

actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);

actionBar.setIcon(R.drawable.ic_blank);

GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
new int[] {
0xFF004700, 0xFF002900
});

gd.setCornerRadius(0f);

actionBar.setBackgroundDrawable(gd);

// set the title of the action bar using the given title
actionBar.setTitle(mTitle);

}

如有任何建议,我们将不胜感激!

最佳答案

如果您希望通过点击 ActionBar 的图标/标题打开抽屉,我建议您使用支持库(android.support.v4.app. ActionBarDrawerToggle)

引用: https://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html

使用示例:
https://developer.android.com/training/implementing-navigation/nav-drawer.html

当在 onOptionsItemSelected() 中捕获事件时,技巧就来了,您必须将它传递给 ActionBarDrawerToggle,以便它可以处理打开/关闭抽屉请求:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...

return super.onOptionsItemSelected(item);
}

关于android - 通过操作栏标题切换抽屉导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18661222/

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