如何在android中为TabHost添加单独的布局和类?

时间:2015-08-26 04:33:22

标签: android

我的基本布局如下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"   
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="lk.abanservice.shankan.abansserviceapp.CheckStatus">

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget android:id="@android:id/tabs"
            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">

            <LinearLayout
                android:id="@+id/checkSerach"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

            </LinearLayout>

            <LinearLayout
                android:id="@+id/checkDisplayAll"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

            </LinearLayout>

        </FrameLayout>
    </LinearLayout>
</TabHost>

所以我需要将以下单独的文件和类添加到此

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/title_request"
    android:id="@+id/textViewTitleRequestt"
    android:textStyle="bold" />

我尝试了几种方法来做到这一点,它可以使用TabActivity,但已从Android 11中删除。任何人有解决方案吗?

我想开发以下接口

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

这是标签主机示例..根据您的要求更改变量和类名...

MainActivity.java

$(function() {

    $('#selection').change(function () {
        var tag = $(this).val();
        $(".main_text").html("<" + tag + ">Change Headings</" + tag + ">");
    });

    $('#color_picker').change(function() {
        var color_p = $(this).val();
        $('.main_text').css("color", color_p);
    });

    $('#select_font').change(function () {
        var change_font = $(this).val();
        $(".main_text").css("font-family", change_font);
    });

    $("#change_font_size").change(function() {
        var font_size = $(this).val();
        $('.main_text').css("font-size", font_size + "px");
    });
}); 

activity_main.java

public class MainActivity extends TabActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TabHost tab = getTabHost();

    TabSpec news = tab.newTabSpec("New");
    news.setIndicator("Check New Job");
    Intent intent = new Intent(MainActivity.this,First.class);
    news.setContent(intent);

    TabSpec old = tab.newTabSpec("Old");
    old.setIndicator("Check Old Job");
    Intent intent_old = new Intent(MainActivity.this,Second.class);
    old.setContent(intent_old);

    tab.addTab(news);
    tab.addTab(old);
    }
 }