使用这个控件的时候在 style中找到这个是默认的焦ActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
colorPrimaryDark是顶栏的颜色
colorPrimary是Toolbard的背景颜色
添加
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">现在把ActionBar给隐藏起来了现在开始使用ToolBar在activity_main.xml中<?xml version="1.0" encoding="utf-8"?> <FrameLayout 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.example.yxw.shipingwangzhang.MainActivity"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> </FrameLayout>就把ToolBar设置好了
在MainActivity
package com.example.yxw.shipingwangzhang; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.Toolbar; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar); setSupportActionBar(toolbar); } }