簡體   English   中英

向TabActivity添加搜索功能

[英]Adding Search functionality to TabActivity

根據我的應用程序需求,我創建了一個擴展TabActivity的活動,並為這些選項卡添加了選項卡和其他活動作為內容。 到此為止一切正常,但是我想向整個TabActivity添加搜索功能,這意味着搜索是在TabHost的頂部完成的,它應該反映所有選項卡內容的搜索。

我知道如何將搜索添加到單個活動中,但是我沒有找到解決我問題的方法。

如果您知道執行此操作的任何步驟,請提出建議。

根據文檔,不建議使用TabActivity:

http://developer.android.com/reference/android/app/TabActivity.html

您應該使用FragmentTabHost或超贊的SherlockActionBar庫。

實現這些現代方法之一后,只需在菜單中添加searchView菜單項即可。

您可以先嘗試在活動jus中托管搜索欄,然后再添加如下面的代碼中所示的tabhost。 並通過添加文本觀察器來實現搜索功能

     public class MyTabActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_xml_with_search_bar);

    }
}

tab_xml_with_search_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Search text"
        />

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@android:id/tabhost"
    android:layout_width="match_parent"
     android:layout_height="match_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>


</TabHost>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM