就个人而言,我可能会将我的
Activity子类始终写到
setContentView一个布局文件中,该文件
fill_parent
LinearLayout包含仅包含标题栏的垂直文件:
<LinearLayout android:id="@+id/custom_titlebar_container" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!--titlebar here--></LinearLayout>
然后,我将定义一个抽象
getContentAreaLayoutId()方法,
CustomTitlebarActivity该方法
ID为每个子类返回标题栏下方内容的布局;底座
onCreate()的
CustomTitlebarActivity,然后只需调用
setContentView(R.layout.custom_titlebar_activity_frame_from_above);View.inflate(this, getContentAreaLayoutId(), findViewById(R.id.custom_titlebar_container));
或者,您可以使用抽象方法来使内容区域返回a
View而不是an
int,从而为您提供了更大的灵活性来动态地构建视图(但是在 这种 情况下,
仅 通过简单地 转储此XML布局就可以 迫使您自己对其进行膨胀)。



