在 MainActivity.class
上,我通过 onSearchRequested()
调用搜索对话框。如上图所示。
我想删除那个主页/应用程序图标,但没有成功。请不要混淆我想删除操作栏上的主页/应用程序图标。不,这是我在 SearchActivity.class
public class SearchableActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_searchable);
// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}}
和 xml/searchable.xml
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer">
关于 AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity" >
<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=".SearchableActivity"/>
</activity>
<activity
android:name=".SearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
</application>
这是我用过的v21/styles.xml
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/orange</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@color/darkorange</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/brown</item>
<!-- title bar text color -->
<item name="android:textColorPrimary">@color/white</item>
<!-- no action bar -->
<item name="android:windowNoTitle">true</item>
</style>
如果你不介意的话,再问一个问题。当我为状态栏声明 darkorange
颜色时,效果很好。但是当 onSearchRequested()
被调用时,状态栏变为黑色(如上图)。我该如何解决?
最佳答案
根据您的情况尝试其中一种
getSupportActionBar().setDisplayShowHomeEnabled(false);
或
getActionBar().setIcon(new
ColorDrawable(getResources().getColor(android.R.color.transparent)));
关于android 搜索界面 - 如何在调用 onSearchRequested() 时删除应用程序图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28199451/