我想让用户知道他正在使用选项卡的应用程序页面。因此,如果他在第一页上,则第一页选项卡将点亮,如果他在第二页上,则第二页选项卡将点亮等。但我想要它,以便选项卡没有任何功能。它们在所有页面上都保持不变(亮起的除外)并且没有触摸/点击事件。我应该为此使用标签还是有更好的选择?我究竟如何使用选项卡来完成此操作以获得更好的选择?提前致谢
最佳答案
可能最好的方法是完全避免使用选项卡小部件,而只需使用排列在 LinearLayout 之类的容器中的 TextView 滚动自己的小部件。
<?xml version="1.0" encoding="utf-8"?>
<!-- Top-level layout for page -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Tab Bar -->
<LinearLayout
android:id="@+id/tab_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- Tab 1 -->
<TextView
android:id="@+id/tab_bar_file"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/file_label"/>
<!-- Tab 2 -->
<TextView
android:id="@+id/tab_bar_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/edit_label"/>
<!-- More tabs go here -->
</LinearLayout>
<!-- Page content goes here -->
</LinearLayout>
一些注意事项:
- 您可以在 TextView 上设置填充 扩大选项卡大小。您可以设置一个 可绘制背景(包括 颜色或图像资源)到 更改选项卡的“外观”,如 以及设置文本样式。
- 您可以将标签栏的封闭 LinearLayout 提取到
单独的 XML 文件,然后使用
<include>
纳入指令 它进入任何布局需要 显示选项卡。 - 在您的 Java 代码中,您只需更改 任何选项卡的样式/颜色 当前,为用户突出显示它。
关于android - android中的伪标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6524331/