Is there any way that search view (after tap/click) expands over android launcher icon like over app title name?
Or maybe, is there a way to change my title to look like launcher icon (like on sreenshot) with some custom font..?
Screenshot:
Using this code inside of my onCreateOptionsMenu()
worked:
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setMaxWidth(5000);
searchView.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ActionBar actionBar = getActionBar();
if (actionBar != null)
actionBar.setDisplayShowHomeEnabled(false);
}
});
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
ActionBar actionBar = getActionBar();
if (actionBar != null)
actionBar.setDisplayShowHomeEnabled(true);
return false;
}
});
Note:
For me the Home Icon was not hidden by default as @MattT. suggested, so I hide it manually when the search is opened and show it again when the search is closed. Also note that getActionBar()
requires API 14+.
If you're interested, before using searchView I inflate my custom layout:
getMenuInflater().inflate(R.menu.actionbar_items, menu);
Where the layout ( menu/actionbar_items.xml ) is this:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:actionViewClass="android.widget.SearchView"
android:showAsAction="always"/>
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:showAsAction="never" />
</menu>
Here is an example I have used in the past to create that type of search view. http://www.edumobile.org/android/android-development/action-bar-search-view/
Also the action bar should by default take your launcher icon unless you specifically set an android:logo attribute. You can also modify this programmatically using the setLogo() method on actionbar.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.