我不認爲這可以通過主持單獨實現。您將需要創建一個抽象Activity
,其中將包括您的標題欄和包裹由擴展Activity
類設置的內容視圖。這裏有一個例子:
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
android:id="@+id/titleBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/titlebar" />
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
摘要活動
public abstract class TitleBarActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.title_bar_activity);
}
@Override
public void setContentView(int layoutResId) {
FrameLayout contentFrameLayout = (FrameLayout) findViewById(R.id.content);
contentFrameLayout.removeAllViews();
getLayoutInflater().inflate(layoutResId, contentFrameLayout);
}
}
這是一個非常簡單的實現,但應該給你的,你需要做的總體思路。現在,對於延伸TitleBarActivity
的任何活動,默認情況下,您的頂部都會有標題欄。標題中的任何自定義你希望你的活動來控制,加入TitleBarActivity
的方法來做到這一點。
我想知道的是:「在佈局我怎麼能在一個主題定義它(自定義標題欄)這與其說是?」。這是我如何刪除默認標題欄... –