android - 在xml文件中添加标签栏

标签 android xml android-layout android-tabhost

我已经创建了 xml 文件并完成了我的项目

现在我想在我的 xml 文件中添加底部标签栏

这是我的xml文件代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/main_bg" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

>
<!-- Logo -->
<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="40dip" android:layout_alignParentTop="true"
    android:background="@drawable/tab_bar" android:id="@+id/rel_jobDesc">

 <!--   <Button android:id="@+id/option"
         style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"   android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"  
        android:background="@drawable/skills"
        android:layout_centerVertical="true" android:text=""
         ></Button> 
         -->

    <TextView android:layout_width="wrap_content"   android:id="@+id/txt_SEARCH_TITLE"
        android:layout_height="wrap_content" android:layout_centerInParent="true"
        android:text="Job Search" android:textStyle="bold" android:textSize="20dip"
        android:textColor="#fff"></TextView>
    <Button android:id="@+id/btnAboutus"
        android:layout_width="wrap_content"     android:layout_height="wrap_content"
        android:layout_alignParentRight="true"  android:background="@drawable/draw"
        android:layout_centerVertical="true" android:text="About Us"
         ></Button>

    <Button
        android:id="@+id/option"
        android:background="@drawable/hamburger"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
         />

</RelativeLayout>

<LinearLayout
    android:id="@+id/l1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/rel_jobDesc" >

   <ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
   android:layout_below="@+id/logo"

   android:layout_marginTop="20dp"

   android:layout_marginLeft="2dp"
    android:layout_marginRight="2dp" >


 <RelativeLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:layout_marginTop="55dip" android:layout_marginLeft="2dip"
    android:layout_marginRight="2dip">


<!--JOB DESCRIPTION -->
<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:id="@+id/txt_JOB_DESCRIPTION"
    android:layout_marginLeft="20dip" android:text="Job Description:"
    android:layout_marginTop="20dip"
     android:textStyle="bold"
    android:textSize="14dip" android:textColor="#000000"
    ></TextView>
    <EditText
     android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:id="@+id/edit_JOB_DESCRIPTION"
    android:layout_toRightOf="@+id/txt_JOB_DESCRIPTION"
    android:maxLines="1" 
     android:background="@android:drawable/editbox_background"
    android:singleLine="true"
    android:layout_marginTop="10dip" android:layout_marginRight="20dip"
    ></EditText>
<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:id="@+id/txt_JDESCRIPTION"
    android:layout_marginLeft="45dip" android:text="(Job title, industry,  keywords)"
    android:textSize="12dip" android:textColor="#4a596e"
    android:layout_below="@+id/edit_JOB_DESCRIPTION"
    android:layout_centerInParent="true"></TextView>
<!-- -->

<!--LOCATION -->

<TextView
    android:id="@+id/txt_JOB_LOCATION"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/txt_JDESCRIPTION"
    android:layout_marginLeft="20dip"
    android:layout_marginTop="50dip"
    android:layout_toLeftOf="@+id/btn_SEARCH"
    android:text="Location:          "
    android:textColor="#000000"
    android:textSize="15dip"
    android:textStyle="bold" >
 </TextView>

<EditText
android:id="@+id/edit_JOB_LOCATION"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/edit_JOB_DESCRIPTION"
android:layout_below="@+id/txt_JDESCRIPTION"
android:layout_marginRight="20dip"
android:layout_marginTop="40dip"
android:background="@android:drawable/editbox_background"
android:maxLines="1"
android:singleLine="true" >
 </EditText>
<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:id="@+id/txt_JLOCATION"
    android:layout_marginLeft="45dip" android:text="(City, State, Zip)"
    android:textSize="12dip" android:textColor="#4a596e"
    android:layout_below="@+id/edit_JOB_LOCATION"
    android:layout_centerInParent="true"></TextView>
<!-- -->


<!-- JOB ID -->
<!-- -->



<!-- SEARCH BUTTON -->

<Button
    android:id="@+id/btn_SEARCH"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/txt_JLOCATION"
    android:layout_centerInParent="true"
    android:layout_marginTop="55dip"
    android:background="@drawable/draw"
    android:text=" Search " >
 </Button>
<!-- -->

</RelativeLayout>

  </ScrollView>

</LinearLayout>


</RelativeLayout>

请建议我如何在我的 xml 文件中添加底部标签栏

感谢任何帮助

提前致谢

最佳答案

你可以这样添加-

    <?xml version="1.0" encoding="utf-8"?>
    <TabHost
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <RelativeLayout
            android:layout_height="fill_parent"
            android:layout_width="fill_parent">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_alignParentBottom="true"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="5dp" />
        </RelativeLayout>
</TabHost>

在上面的代码中,android:layout_alignParentBottom=”true” 用于将其对齐到底部。

在 Activity 课上-

    Intent intent;

    intent = new Intent().setClass(this, FirstActivity.class);
    spec = tabHost.newTabSpec("First").setIndicator("First")
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, SecondActivity.class);
    spec = tabHost.newTabSpec("Second").setIndicator("Second")
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, ThirdActivity.class);
    spec = tabHost.newTabSpec("Third").setIndicator("Third")
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, FourthActivity.class);
    spec = tabHost.newTabSpec("Fourth").setIndicator("Fourth")
                  .setContent(intent);
    tabHost.addTab(spec);

关于android - 在xml文件中添加标签栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20877721/

相关文章:

android - 膨胀包含自己的 View 的自定义 View 时出现 StackOverflowError

android - 在android中绘制三角形背景

php - 使用json在android中通过php更新mysql

Android App 长时间闲置后崩溃

xml - XSLT 1.0 获取当前日期时间

android - 动态添加数据行

android - 在真正的android设备上找不到res/color/filename.xml资源文件

java - 如何解决此错误 : cannot find symbol class DragAdapter

java - 如何在mainActivity中初始化界面

c# - 将 XML 加载到内存流中