ToolBar

comment_toolbar.xml




main.xml


Activity

package com.imooc.food;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

/**
 * Created by Administrator on 2018/3/13.
 */

public class BasicActity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
  if (Build.VERSION.SDK_INT>Build.VERSION_CODES.LOLLIPOP){
      getWindow().setStatusBarColor(0xff000000);
  }
/**
 * 判断版本如果大于21则标题栏显示黑色.
 */
    }
    protected void getToolBar(){
        Toolbar toolbar=(Toolbar)findViewById(R.id.toobar);
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });

    }
}

你可能感兴趣的:(ToolBar)