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); }