带导航抽屉的工具栏按钮

时间:2017-11-27 17:50:29

标签: android android-toolbar

我有一个带导航抽屉的工具栏。我想用导航栏做一个与图片相同的工具栏。

enter image description here 我有几个问题:
1)出现三个点而不是按钮图标。
2)只有当我点击这三个点(如下拉列表)时才会出现按钮标题。

enter image description here

我用ToolBar尝试过很多例子,但仍然没有成功。也许它是由DrawerLayout引起的......也许有人知道它是由什么引起的?

主要活动:

public class CourierActivity extends AppCompatActivity {
    private ActionBarDrawerToggle mToggle;
    private DrawerLayout mDrawerLayout;
    private NavigationView nv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.courier_main);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
        mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.menu_open, R.string.menu_close);
        mDrawerLayout.addDrawerListener(mToggle);
        mToggle.syncState();

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        NavigationView nv = (NavigationView) findViewById(R.id.navmenu);
        nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem menuItem) {
                switch (menuItem.getItemId()) {
                    // ...
                }

                return true;
            }
        });

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater me = getMenuInflater();
        me.inflate(R.menu.actionbar, menu);

        return super.onCreateOptionsMenu(menu);
    }
}

@菜单/动作条:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:title="Item"
        android:id="@+id/refresh"
        android:icon="@android:drawable/bottom_bar"
        android:showAsAction="ifRoom"
        android:visible="true" />
</menu>

@布局/ main_layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.example.seether.myapplication.CourierActivity"
    android:background="#fff"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawerLayout">


    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:menu="@menu/navigation_menu"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigation_layout"
        android:id="@+id/navmenu">

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


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

@菜单/ navigation_menu:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/orders"
        android:icon="@mipmap/ic_event_black_24dp"
        android:title="@string/orders" />

    <item
        android:id="@+id/settings"
        android:icon="@mipmap/ic_settings_black_24dp"
        android:title="@string/settings" />

    <item
        android:id="@+id/logout"
        android:icon="@mipmap/ic_exit_to_app_black_24dp"
        android:title="@string/logout" />

</menu>

0 个答案:

没有答案