AppCompatActivity工具栏的设置(返回操作)

<android.support.v7.widget.Toolbar 
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id
="@id/toolbar"
android:background
="?colorPrimary"
android:layout_width
="fill_parent"
android:layout_height
="?actionBarSize"
android:minHeight
="?actionBarSize"
app:popupTheme
="?actionBarPopupTheme"
app:navigationIcon
="?homeAsUpIndicator"
xmlns:app
="http://schemas.android.com/apk/res-auto" />

设置工具栏,返回操作

    private void setToolbar() {
        View locView = findViewById(R.id.toolbar);
        setSupportActionBar((Toolbar) locView);
        ((Toolbar) locView).setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SettingsActivity.this.onBackPressed();
            }
        });
    }

 

posted on 2016-03-22 15:37  寻步  阅读(795)  评论(0编辑  收藏  举报