Search in sources :

Example 1 with LayoutParams

use of android.app.ActionBar.LayoutParams in project coursera-android by aporter.

the class DialtactsActivity method prepareSearchView.

private void prepareSearchView() {
    final View searchViewLayout = getLayoutInflater().inflate(R.layout.dialtacts_custom_action_bar, null);
    mSearchView = (SearchView) searchViewLayout.findViewById(R.id.search_view);
    mSearchView.setOnQueryTextListener(mPhoneSearchQueryTextListener);
    mSearchView.setOnCloseListener(mPhoneSearchCloseListener);
    // Since we're using a custom layout for showing SearchView instead of letting the
    // search menu icon do that job, we need to manually configure the View so it looks
    // "shown via search menu".
    // - it should be iconified by default
    // - it should not be iconified at this time
    // See also comments for onActionViewExpanded()/onActionViewCollapsed()
    mSearchView.setIconifiedByDefault(true);
    mSearchView.setQueryHint(getString(R.string.hint_findContacts));
    mSearchView.setIconified(false);
    mSearchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                showInputMethod(view.findFocus());
            }
        }
    });
    if (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
        // Filter option menu should be shown on the right side of SearchView.
        final View filterOptionView = searchViewLayout.findViewById(R.id.search_option);
        filterOptionView.setVisibility(View.VISIBLE);
        filterOptionView.setOnClickListener(mFilterOptionClickListener);
    }
    getActionBar().setCustomView(searchViewLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
Also used : OnFocusChangeListener(android.view.View.OnFocusChangeListener) LayoutParams(android.app.ActionBar.LayoutParams) View(android.view.View) ContactListItemView(com.android.contacts.list.ContactListItemView) SearchView(android.widget.SearchView)

Aggregations

LayoutParams (android.app.ActionBar.LayoutParams)1 View (android.view.View)1 OnFocusChangeListener (android.view.View.OnFocusChangeListener)1 SearchView (android.widget.SearchView)1 ContactListItemView (com.android.contacts.list.ContactListItemView)1