Theme.Appcompat.Light
// 修改actionbar背景颜色
<item name="colorPrimary">@color/colorPrimary</item>
//修改状态栏颜色5.0以上
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
// 修改控件的主体颜色
<item name="colorAccent">@color/colorAccent</item>
在res/menu/xxxxx.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
yourapp:showAsAction="ifRoom" />
...
</menu>
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<!--内容-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
</LinearLayout>
<!--菜单-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#f00"/>
</android.support.v4.widget.DrawerLayout>
ActionBar&DrawerLayout联动android
// 显示返回箭头 或者 home按钮
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerlayout);
//ActionBarDrawerToggle
mActionBarDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, R.string.open,R.string.close);
mDrawerLayout.addDrawerListener(mActionBarDrawerToggle);
//同步状态
mActionBarDrawerToggle.syncState();
/actionbar上按钮的点击/app
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mActionBarDrawerToggle.onOptionsItemSelected(item)){ return true;//消费 } /* int itemId = item.getItemId(); if (itemId == android.R.id.home){ Toast.makeText(MainActivity.this, "home按钮被点击了", Toast.LENGTH_SHORT).show(); }*/ return super.onOptionsItemSelected(item); }