我想为应用程序中的每个 Activity 重用页脚等选项卡。
我正在使用这个代码
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="@android:id/tabs" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</TabHost>
我想在每个布局的选项卡顶部添加 ListView、Button 等组件。我该如何管理?
最佳答案
我通过扩展一个公共(public)基础 Activity 做了类似的事情,我在其中重写了方法 setContentView。
abstract public class BaseActivity extends Activity {
@Override
public void setContentView(View view) {
// get master
LayoutInflater inflater = LayoutInflater.from(this);
// this is the master view with a container and the footer, you can
// as well add the header
RelativeLayout rlMasterView = (RelativeLayout) inflater.inflate(R.layout.master, null);
rlMasterView.addView(view);
super.setContentView(rlMasterView);
}
}
setContentView 创建页脚并将其附加到我在每个 Activity 中设置的 View 。
我也可以在每个布局中使用 include 标签。
<include src="footer" />
关于像页脚一样的 Android 选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8656156/