第一个问题: 我想创建一个从右到左的工具栏,如下图所示:
如何自定义工具栏DrawerArrowToggle向右移动?
第二个问题: 我创建一个自定义工具栏并为打开的抽屉创建一个按钮,但工具栏DrawerArrowToggle出现在我的自定义工具栏的左侧。 如何删除它?
- 更新 -
感谢sasikumar添加此行,删除了DrawerArrowToggle。
mDrawerToggle.setDrawerIndicatorEnabled(false);
这是我的工具栏代码:
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.action_bar, null);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(view, new ActionBar.LayoutParams
(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
Toolbar parent = (Toolbar) view.getParent();
parent.setContentInsetsAbsolute(0, 0);
Drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, Drawer,
parent, R.string.openDrawer,
R.string.closeDrawer) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item != null && item.getItemId() == android.R.id.home) {
if (Drawer.isDrawerOpen(Gravity.RIGHT)) {
Drawer.closeDrawer(Gravity.RIGHT);
} else {
Drawer.openDrawer(Gravity.RIGHT);
}
}
return false;
}
};
Drawer.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
我的渴望应用程序是这样的:
抱歉英语不好。答案 0 :(得分:2)
您可以使用onDrawerSlide方法隐藏箭头。
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
getToolbar(), R.string.open, R.string.close) {
@Override
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, 0); // this disables the animation
}
};
如果您想完全删除箭头,可以添加
super.onDrawerSlide(drawerView, 0); // this disables the arrow @ completed state
在onDrawerOpened函数的末尾
答案 1 :(得分:1)
检查以下链接,可能会有所帮助:
How can I open navigation drawer from right side to left
也是这个链接:
Android - Is Navigation Drawer from right hand side possible?
答案 2 :(得分:1)
似乎您已添加剩余代码。只需将抽屉组件的重力设置为右侧。 喜欢......
android:layout_gravity="right"
现在使用以下代码将抽屉位置设置为右侧:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, R.string.drawer_open,
R.string.drawer_close) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item != null && item.getItemId() == android.R.id.home) {
if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
mDrawerLayout.closeDrawer(Gravity.RIGHT);
} else {
mDrawerLayout.openDrawer(Gravity.RIGHT);
}
}
return false;
}
};