1

我是android的新手,我正在创建一个测试程序来测试search dialogandroid。这是searchable.xml配置文件

<?xml version="1.0" encoding="utf-8"?>
<searchable 
      xmlns:android="http://schemas.android.com/apk/res/android" 
   android:label="Search"
   android:hint="Type text to search">
</searchable> 

这是清单文件

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="luan.com.bk"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity android:name=".SearchActivity" >
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </activity>

        <activity
            android:name=".TestActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <meta-data
                android:name="android.app.default_searchable"
                android:value=".SearchActivity" />
        </activity>
    </application>
</manifest>

这是请求搜索的searchActivity.java

    package luan.com.bk;

import android.app.Activity;
import android.os.Bundle;

public class SearchActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }
}

这是testActivity.java初始化搜索对话框

    package luan.com.bk;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class TestActivity extends Activity {
    /** Called when the activity is first created. */


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

但是当我在android模拟器上按搜索键按钮时,搜索栏不显示,我怎么了?请帮忙。对不起,因为我的英语不好。

4

0 回答 0