set ActionBarDrawerToggle at right corner
How can i set ActionBarDrawerToggle at right corner ? because i set listview gravity
android:layout_gravity="end"
so i want ActionBarDrawerToggle to be at right , How can i do that ??
this is my code
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout,R.drawable.ic_drawer,R.string.drawer_open,R.string.drawer_close)
{
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu();
}
};
I can't do this using the click on "home" icon, and I think this wouldn't be good because drawer will appear in the right side. But, as @runamok, I want to have an option menu item (as opposed to replacing the "home" icon which normally performs "back" functionality) on the right side which triggers the drawer to transition in/out from the right.
Besides using android:layout_gravity="right", use an option menu item to perform the open/close movement.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.my_menu_item:
if(!mDrawerLayout.isDrawerOpen(Gravity.RIGHT))
mDrawerLayout.openDrawer(Gravity.RIGHT);
else
mDrawerLayout.closeDrawer(Gravity.RIGHT);
return true;
default:
break;
}
return super.onOptionsItemSelected(item);
}
回答
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.my_menu_item:
if(!mDrawerLayout.isDrawerOpen(GravityCompat.END))
mDrawerLayout.openDrawer(GravityCompat.END);
else
mDrawerLayout.closeDrawer(GravityCompat.END);
return true;
default:
break;
}
return super.onOptionsItemSelected(item);
}
尝试将此行添加到Android清单文件中:
android:supportsRtl="true"
链接地址: http://www.djcxy.com/p/72954.html