Android的:如何宣布任何活动为主要和搜索?Android

2023-09-06 13:48:09 作者:柚绿时光

我想我的主要活动是搜索的同时,但是当我在manifest.xml的改变

I would like my main activity to be searchable also but when I change the manifest.xml to

 <intent-filter>
       <action android:name="android.intent.action.MAIN" />
       <category android:name="android.intent.category.LAUNCHER" />
       <!-- declare the default searchable Activity for the whole app -->
       <action android:name="android.intent.action.SEARCH" />            
 </intent-filter>

它不能找到主要活动和应用程序不运行。 任何想法? 是它不使用相同的活性也可搜索的最佳实践? 谢谢, 阿利萨

it cant find the main activity and the application doesn't run. any idea? is it not best practice to use the same activity as searchable also? Thanks, Alisa

推荐答案

您需要添加一个新的意图过滤器与action.SEARCH

You need to add a new intent-filter with the action.SEARCH

<activity
    android:name=".activities.YourActivity">
    <intent-filter>
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.MAIN" />
    </intent-filter>
     <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
    </intent-filter>
</activity>
 
精彩推荐
图片推荐