ActionBarDrawerToggle在右边

时间:2014-06-21 06:04:30

标签: android android-layout

我正在使用ActionBarDrawerToggle(导航抽屉),但我无法在右上角设置它(对于波斯语)。

这是我的activity_main.xml代码:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Framelayout to display Fragments -->
    <FrameLayout   
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />  

    <!-- Listview to display slider menu -->
    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"  
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"        
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background" />

</android.support.v4.widget.DrawerLayout>

这是我的活动类的相关代码:

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
    R.drawable.ic_drawer, //nav menu toggle icon
    R.string.app_name, // nav drawer open - description for accessibility
    R.string.app_name // nav drawer close - description for accessibility) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            // calling onPrepareOptionsMenu() to show action bar icons
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            // calling onPrepareOptionsMenu() to hide action bar icons
            invalidateOptionsMenu();
        }          
}; 

我搜索了这个,我应该使用重力,但它不能用于xml。

2 个答案:

答案 0 :(得分:2)

toolbar.setNavigationOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
    if (Drawer.isDrawerOpen(Gravity.RIGHT)) {
        Drawer.closeDrawer(Gravity.RIGHT);
    } else {
        Drawer.openDrawer(Gravity.RIGHT);
    }
}});

答案 1 :(得分:-2)

尝试将此行添加到android清单文件中:

android:supportsRtl="true"