开发者

Android 3.0 honeycomb search view on action bar

开发者 https://www.devze.com 2023-03-19 02:05 出处:网络
How to have a \'search item\' on the action bar for honeycomb? If possible please pro开发者_StackOverflow社区vide full code with layout.I\'m assuming you mean adding the search widget to the actionbar

How to have a 'search item' on the action bar for honeycomb? If possible please pro开发者_StackOverflow社区vide full code with layout.


I'm assuming you mean adding the search widget to the actionbar? Here's how it's done:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_search"
        android:title="Search"
        android:icon="@drawable/ic_menu_search"
        android:showAsAction="ifRoom"
        android:actionViewClass="android.widget.SearchView" />
</menu>

This is of course placed in the res/menu folder.

You add this to your actionbar just like any adding any other menu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.options, menu);
  SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
  // Set appropriate listeners for searchView
  ...
  return super.onCreateOptionsMenu(menu);
}

This was all taken from here: http://developer.android.com/guide/topics/ui/actionbar.html#ActionView

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号