像页脚一样的 Android 选项卡

标签 android tabs footer

我想为应用程序中的每个 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/

相关文章:

android - 替换括号内的字符

jquery - Bootstrap Tab View 内容未显示

java - ActionBar 的选项卡标题中的自定义字体

html - 合并外部 div 与内部 div 和内部 div 边框事件

android - 在没有新 Intent 的情况下,我应该如何从通知返回到 Activity

android - 启动 Google Assistant 语音交互

html - DIV 而非文本的响应中心对齐

javascript - 为什么 css 页脚链接不起作用?

android - 获得一个简单的 throw 手势

html - 如何使用CSS将页脚放在底部?