标签:
1.配置 activity的主题:
android:theme="@style/AppThemeBB"
2. 通过Menu.xml文件布局 添加菜单item
menu/menu.xml
main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_personal"
android:icon="@drawable/action_personal"
android:orderInCategory="100"
android:showAsAction="always"
android:title="@string/action_personal"/>
<item
android:id="@+id/menu_collapse"
android:actionLayout="@layout/actionbar_center_title"
android:icon="@drawable/action_personal"
android:showAsAction="ifRoom|withText"
android:title="@string/action_personal">
</item>
</menu>
actionbar_center_title.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="45dp"
android:layout_marginRight="45dp"
android:background="@null"
android:id="@+id/actionbar2"
>
<TextView
android:id="@+id/actionbar_center_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:gravity="center"
android:text="as"
android:textColor="@color/txt_black"
android:textSize="18sp" />
</RelativeLayout>
3.在activity中获得资源
/**
* 加载菜单
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
//------
RelativeLayout viewGroup = (RelativeLayout) menu.findItem(R.id.menu_collapse).getActionView();
tvTitle= (TextView)viewGroup.findViewById(R.id.actionbar_center_title);
tvTitle.setText("ssssss");
return true;
}
4.在左侧导航listview中添加监听
mMenuListView.setOnItemClickListener(new DrawerItemClickListener());
/**
* ListView上的Item点击事件
*
*/
private class DrawerItemClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
selectItem(position);
tvTitle.setText(mMenuTitles[position]);
}
}
标签:
原文地址:http://www.cnblogs.com/manmanlu/p/4397639.html