android中的伪标签

时间:2011-06-29 16:50:42

标签: android android-layout tabs

我想让用户知道他使用标签的应用程序页面。因此,如果他在第一页上页面一个标签将被点亮,如果他在第二页,页面两个标签将被点亮等。但我想要它,以便标签没有任何功能。它们在所有页面上保持相同(执行点亮的内容)并且没有触摸/点击事件。我应该使用标签还是有更好的选择?我如何通过选项卡实现更好的选择呢?提前致谢

1 个答案:

答案 0 :(得分:1)

执行此操作的最佳方法可能是避免完全使用制表符小部件,只需使用排列在像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>

关于此的一些注意事项:

  1. 您可以在TextView上设置填充 扩展选项卡大小。你可以设置一个 背景可绘制(包括一个 颜色或图像资源) 更改选项卡的“外观”,如 以及文字的风格。
  2. 您可以将标签栏的封闭LinearLayout提取为 单独的XML文件,然后使用 要加入<include>指令 它适用于任何需要的布局 显示标签。
  3. 在您的Java代码中,您只需更改即可 任何标签的样式/颜色是 当前,为用户突出显示它。