自定义ActionBar完全覆盖Title

效果图:

实现方法:

@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.// getMenuInflater().inflate(R.menu.main, menu);setActionBarLayout(R.layout.actionbarlayout, this);return true;}/** * 设置ActionBar的布局 * * @param layoutId *布局Id * * */@SuppressLint("NewApi")public void setActionBarLayout(int layoutId, Context mContext) {ActionBar actionBar = getActionBar();if (null != actionBar) {actionBar.setDisplayShowHomeEnabled(false);actionBar.setDisplayShowCustomEnabled(true);actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);View v = inflator.inflate(layoutId, new LinearLayout(mContext),false);ActionBar.LayoutParams layout = new ActionBar.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);actionBar.setCustomView(v, layout);}}actionbarlayout.xml:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=""android:layout_width="match_parent"android:layout_height="match_parent"android:background="#FFFF8824"android:orientation="horizontal" ><Buttonandroid:id="@+id/btnActionBarBack"android:layout_width="0px"android:layout_height="fill_parent"android:layout_weight="2"android:text="test" /><TextViewandroid:id="@+id/tvActionBarName"android:layout_width="0px"android:layout_height="fill_parent"android:layout_weight="6"android:gravity="center"android:text="Hello" /><Buttonandroid:id="@+id/btnActionBarSearch"android:layout_width="0px"android:layout_height="match_parent"android:layout_weight="2"android:text="test" /></LinearLayout>源码下载地址:

转载请注明出处:

,的这一半更多地赢取上帝掌握的那一半。

自定义ActionBar完全覆盖Title

相关文章:

你感兴趣的文章:

标签云: