尽管导航栏切换导航栏导航

时间:2017-07-14 02:04:30

标签: android android-actionbar navigation-drawer android-toolbar

我使用片段实现了抽屉导航。按照谷歌教程实施后,汉堡包图标显示在左侧。但是当我对我的工具栏xml进行更改以在中心添加textview时,它会向左移动,我假设抽屉切换但我在xml或main.java中的任何地方都看不到它。这就是我的mainActivity类onCreate方法所设置的导航栏我认为(我再次使用了抽屉活动类):

public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}

这是我的app栏的app,app_bar_main.xml

 <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.closedbracket.drawernav.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center">

                <TextView
                    android:id="@+id/title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="title "
                    android:textAllCaps="false"
                    android:textColor="@android:color/background_light"
                    android:textSize="22sp"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true" />
            </RelativeLayout>

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>

我还附上一些图片来表明我的意思。第一个图像是app_bar_main.xml的布局,第二个图像是应用程序运行和设置抽屉汉堡包图标时的外观。 app_bar_main.xml layoutThe app during runtime, with the title now shifted left.

我真正需要帮助的是: 1)如何在考虑到切换栏占用空间的同时使标题居中(不仅仅是左边的几个像素,因为它可能随屏幕尺寸而变化?)

2)如何找到切换按钮,以及它放在操作栏中的位置并进行修改?如果我想将它向右移动或在其他地方移动它可能吗?

非常感谢您的帮助或建议!

0 个答案:

没有答案
相关问题