温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android应用中怎么在底端显示选项卡

发布时间:2020-11-24 15:24:14 来源:亿速云 阅读:129 作者:Leah 栏目:移动开发

这篇文章将为大家详细讲解有关Android应用中怎么在底端显示选项卡,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

1.layout 文件

<&#63;xml version="1.0" encoding="utf-8" &#63;>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
  <TabHost android:id="@+id/edit_item_tab_host"
  android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">
      <FrameLayout android:id="@android:id/tabcontent"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:padding="5dp" android:layout_weight="1">
        <LinearLayout android:id="@+id/widget_layout_Blue"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
          <RelativeLayout android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:paddingLeft="3px"
          android:paddingRight="3px">
            <LinearLayout android:id="@+id/titleLayout_person_check_road_add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            </LinearLayout>
            <LinearLayout
            android:id="@+id/layout_person_check_road_add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/titleLayout_person_check_road_add"
            android:layout_alignTop="@id/titleLayout_person_check_road_add"
            android:orientation="vertical">
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
    <LinearLayout android:id="@+id/widget_layout_red"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
      <RelativeLayout android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:paddingLeft="3px" android:paddingRight="3px">
        <LinearLayout android:id="@+id/titleLayout_person_check_road_add1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        </LinearLayout>
        <LinearLayout
        android:id="@+id/layout_person_check_road_add1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/titleLayout_person_check_road_add1"
        android:layout_alignTop="@id/titleLayout_person_check_road_add1"
        android:orientation="vertical">
        </LinearLayout>
    </RelativeLayout>
</LinearLayout>
<LinearLayout android:id="@+id/widget_layout_green"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
  <RelativeLayout android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:paddingLeft="3px" android:paddingRight="3px">
    <LinearLayout android:id="@+id/titleLayout_person_check_road_add2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"> </LinearLayout>
    <LinearLayout android:id="@+id/layout_person_check_road_add2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/titleLayout_person_check_road_add2"
    android:layout_alignTop="@id/titleLayout_person_check_road_add2"
    android:orientation="vertical"> </LinearLayout>
  </RelativeLayout>
</LinearLayout>
<LinearLayout android:id="@+id/widget_layout_yellow"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
  <RelativeLayout android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:paddingLeft="3px" android:paddingRight="3px">
    <LinearLayout android:id="@+id/titleLayout_person_check_road_add3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"> </LinearLayout>
    <LinearLayout android:id="@+id/layout_person_check_road_add3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/titleLayout_person_check_road_add3"
    android:layout_alignTop="@id/titleLayout_person_check_road_add3"
    android:orientation="vertical"> </LinearLayout>
  </RelativeLayout>
</LinearLayout>
</FrameLayout>
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="0" /> </LinearLayout>
</TabHost>
</LinearLayout>

2.Java 文件

import android.app.ActivityGroup;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TabHost;
import android.widget.TextView;
public class TabBottom extends ActivityGroup {
  public static TabHost myTabhost;
  private LayoutParams title_params = new LayoutParams(120, 50);
  private LayoutParams content_params = new LayoutParams(158, 50);
  private LinearLayout titleLayout, showViewLayout, titleLayout1,
  showViewLayout1, titleLayout2, showViewLayout2, titleLayout3,
  showViewLayout3;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bottomtab);
    myTabhost = (TabHost) findViewById(R.id.edit_item_tab_host);
    myTabhost.setup(this.getLocalActivityManager());
    titleLayout = (LinearLayout) findViewById(R.id.titleLayout_person_check_road_add);
    showViewLayout = (LinearLayout) findViewById(R.id.layout_person_check_road_add);
    titleLayout1 = (LinearLayout) findViewById(R.id.titleLayout_person_check_road_add1);
    showViewLayout1 = (LinearLayout) findViewById(R.id.layout_person_check_road_add1);
    titleLayout2 = (LinearLayout) findViewById(R.id.titleLayout_person_check_road_add2);
    showViewLayout2 = (LinearLayout) findViewById(R.id.layout_person_check_road_add2);
    titleLayout3 = (LinearLayout) findViewById(R.id.titleLayout_person_check_road_add3);
    showViewLayout3 = (LinearLayout) findViewById(R.id.layout_person_check_road_add3);
    myTabhost.addTab(myTabhost
    .newTabSpec("One")
    .setIndicator("收件箱",
    getResources().getDrawable(R.drawable.icon))
    .setContent(R.id.widget_layout_Blue));
    myTabhost.addTab(myTabhost
    .newTabSpec("Two")
    .setIndicator("发件箱",
    getResources().getDrawable(R.drawable.icon))
    .setContent(R.id.widget_layout_green));
    myTabhost.addTab(myTabhost
    .newTabSpec("Three")
    .setIndicator("垃圾箱",
    getResources().getDrawable(R.drawable.icon))
    .setContent(R.id.widget_layout_red));
    myTabhost.addTab(myTabhost
    .newTabSpec("Four")
    .setIndicator("发送",
    getResources().getDrawable(R.drawable.icon))
    .setContent(R.id.widget_layout_yellow));
    showInLayout();
    showInLayout1();
    showInLayout2();
    showInLayout3();
  }
  /*
  * 填充第一个选项卡页面
  */
  private void showInLayout() {
    for (int i = 0; i < 10; i++) {
      String condName = "名称显示1";
      TextView tv = new TextView(this);
      tv.setTextColor(Color.WHITE);
      tv.setTextSize(16);
      tv.setLayoutParams(title_params);
      tv.setText(condName + ":");
      titleLayout.addView(tv);
      EditText tv1 = new EditText(this);
      tv1.setTextSize(16);
      tv1.setLayoutParams(content_params);
      tv1.setText(condName);
      showViewLayout.addView(tv1);
    }
  }
  private void showInLayout1() {
    for (int i = 0; i < 10; i++) {
      String condName = "名称显示2";
      TextView tv = new TextView(this);
      tv.setTextColor(Color.WHITE);
      tv.setTextSize(16);
      tv.setLayoutParams(title_params);
      tv.setText(condName + ":");
      titleLayout1.addView(tv);
      TextView tv1 = new TextView(this);
      tv1.setTextColor(Color.WHITE);
      tv1.setTextSize(16);
      tv1.setLayoutParams(content_params);
      tv1.setText(condName + ":");
      showViewLayout1.addView(tv1);
    }
  }
  private void showInLayout2() {
    for (int i = 0; i < 10; i++) {
      String condName = "名称显示3";
      TextView tv = new TextView(this);
      tv.setTextColor(Color.WHITE);
      tv.setTextSize(16);
      tv.setLayoutParams(title_params);
      tv.setText(condName + ":");
      titleLayout2.addView(tv);
      TextView tv1 = new TextView(this);
      tv1.setTextColor(Color.WHITE);
      tv1.setTextSize(16);
      tv1.setLayoutParams(content_params);
      tv1.setText(condName + ":");
      showViewLayout2.addView(tv1);
    }
  }
  private void showInLayout3() {
    for (int i = 0; i < 10; i++) {
      String condName = "名称显示4";
      TextView tv = new TextView(this);
      tv.setTextColor(Color.WHITE);
      tv.setTextSize(16);
      tv.setLayoutParams(title_params);
      tv.setText(condName + ":");
      titleLayout3.addView(tv);
      TextView tv1 = new TextView(this);
      tv1.setTextColor(Color.WHITE);
      tv1.setTextSize(16);
      tv1.setLayoutParams(content_params);
      tv1.setText(condName + ":");
      showViewLayout3.addView(tv1);
    }
  }
}

关于Android应用中怎么在底端显示选项卡就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI