android中的Psuedo标签

android中的Psuedo标签,android,android-layout,tabs,Android,Android Layout,Tabs,我想让用户知道他在使用标签的应用程序的哪个页面上。因此,如果他在第一页,第一页的标签将被点亮,如果他在第二页,第二页的标签将被点亮,等等。但是我想要它,这样标签就没有任何功能了。它们在所有页面上保持不变(执行点亮的内容),并且没有触摸/点击事件。我应该使用标签吗?还是有更好的选择?我如何通过选项卡实现更好的选择?提前感谢最好的方法可能是避免完全使用选项卡小部件,只需使用像LinearLayout这样的容器中排列的文本视图即可 <?xml version="1.0" encoding="ut

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

最好的方法可能是避免完全使用选项卡小部件,只需使用像LinearLayout这样的容器中排列的文本视图即可

<?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上设置填充 展开选项卡大小。你可以设定一个 背景可绘制(包括 颜色或图像资源)以 更改选项卡的“外观”,如下所示 以及为文本设置样式
  • 可以将选项卡栏的封闭线性布局提取到 分离XML文件,然后使用 要合并的指令 它可以转换成任何需要的布局 显示选项卡
  • 在Java代码中,只需更改 选项卡的样式/颜色 当前,为用户突出显示它

  • 最好的方法可能是避免完全使用tab小部件,只需使用像LinearLayout这样的容器中排列的文本视图即可

    <?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上设置填充 展开选项卡大小。你可以设定一个 背景可绘制(包括 颜色或图像资源)以 更改选项卡的“外观”,如下所示 以及为文本设置样式
  • 可以将选项卡栏的封闭线性布局提取到 分离XML文件,然后使用 要合并的指令 它可以转换成任何需要的布局 显示选项卡
  • 在Java代码中,只需更改 选项卡的样式/颜色 当前,为用户突出显示它