当前位置: 首页>>代码示例>>Java>>正文


Java SearchView.findViewById方法代码示例

本文整理汇总了Java中android.support.v7.widget.SearchView.findViewById方法的典型用法代码示例。如果您正苦于以下问题:Java SearchView.findViewById方法的具体用法?Java SearchView.findViewById怎么用?Java SearchView.findViewById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.widget.SearchView的用法示例。


在下文中一共展示了SearchView.findViewById方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreateOptionsMenu

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if(loaderId == DELETED_LOADER_ID){
        inflater.inflate(R.menu.menu_fragment_bin, menu);
    }

    // Place an action bar item for searching.
    MenuItem item = menu.add("Search");
    item.setIcon(R.drawable.ic_search_white_24dp);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM|MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    searchView = new SearchView(myActivity);
    searchView.setMaxWidth(Integer.MAX_VALUE);

    // Set searchbox text to white
    EditText searchEditText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
    searchEditText.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
    searchEditText.setHintTextColor(ContextCompat.getColor(getContext(), R.color.white));

    searchView.setOnQueryTextListener(this);
    item.setActionView(searchView);
    super.onCreateOptionsMenu(menu, inflater);

}
 
开发者ID:danlls,项目名称:Todule-android,代码行数:25,代码来源:ToduleListFragment.java

示例2: setupSearchOptions

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
protected void setupSearchOptions(SearchView searchView) {
    final ImageButton searchOptionsButton =
            (ImageButton) getActivity().getLayoutInflater().inflate(R.layout.search_view_options_button, null);
    LinearLayout searchViewSearchPlate = (LinearLayout) searchView.findViewById(R.id.search_plate);
    searchViewSearchPlate.addView(searchOptionsButton);
    searchOptionsButton.setLayoutParams(
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));
    searchOptionsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearchOptionsButtonClicked();
        }
    });
}
 
开发者ID:graviton57,项目名称:TheNounProject,代码行数:17,代码来源:SearchIconFragment.java

示例3: onCreateOptionsMenu

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_search_view, menu);

        MenuItem searchItem = menu.findItem(R.id.action_search);
        mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        mSearchView.setQueryHint("输入歌曲名查找");

        mSearchView.onActionViewExpanded();// 当展开无输入内容的时候,没有关闭的图标
        mSearchView.setIconified(true);//设置searchView处于展开状态

//        searchView.setSubmitButtonEnabled(true);
        mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                //提交按钮的点击事件
                Toast.makeText(SearchViewActivity.this, query, Toast.LENGTH_SHORT).show();
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                //当输入框内容改变的时候回调
//                Log.i(TAG,"内容: " + newText);
                quertMusic(newText);
                return true;
            }
        });


        mSearchAutoComplete = (SearchView.SearchAutoComplete) mSearchView.findViewById(R.id.search_src_text);

        //设置输入框内容文字和提示文字的颜色
        mSearchAutoComplete.setHintTextColor(getResources().getColor(android.R.color.white));
        mSearchAutoComplete.setTextColor(getResources().getColor(android.R.color.white));

        return super.onCreateOptionsMenu(menu);
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:39,代码来源:SearchViewActivity.java

示例4: onCreateOptionsMenu

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.home_menu_search, menu);

    searchMenuItem = menu.findItem(R.id.action_search);
    searchMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            tryCloseDrawer();
            return false;
        }
    });

    searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            onSearchToolbarTextChanged(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            onSearchToolbarTextChanged(newText);
            return true;
        }
    });

    ImageView closeButton = (ImageView) searchView.findViewById(R.id.search_close_btn);
    closeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchResultsDialog.hide();
            searchView.setQuery("", false);
        }
    });

    return true;
}
 
开发者ID:ABTSoftware,项目名称:SciChart.Android.Examples,代码行数:40,代码来源:HomeActivity.java

示例5: onCreateOptionsMenu

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView =
            (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);
    searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    searchView.setQuery(mPresenter.getSearchModels().get(0).getQuery(), false);
    if (isInputMode) {
        MenuItemCompat.expandActionView(searchItem);
    } else {
        MenuItemCompat.collapseActionView(searchItem);
    }
    MenuItemCompat.setOnActionExpandListener(searchItem, this);

    AutoCompleteTextView autoCompleteTextView = searchView
            .findViewById(android.support.v7.appcompat.R.id.search_src_text);
    autoCompleteTextView.setThreshold(0);
    autoCompleteTextView.setAdapter(new ArrayAdapter<>(this,
            R.layout.layout_item_simple_list, mPresenter.getSearchRecordList()));
    autoCompleteTextView.setDropDownBackgroundDrawable(new ColorDrawable(ViewUtils.getWindowBackground(getActivity())));
    autoCompleteTextView.setOnItemClickListener((parent, view, position, id) -> {
        onQueryTextSubmit(parent.getAdapter().getItem(position).toString());
    });

    return super.onCreateOptionsMenu(menu);
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:29,代码来源:SearchActivity.java

示例6: onCreateOptionsMenu

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.toolbar_menu, menu);
    MenuItem searchItem = menu.findItem(R.id.search);

    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    mSearchAutoComplete = searchView.findViewById(R.id.search_src_text);
    searchView.setOnSearchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switchLayout();
        }
    });
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            switchLayout();
            return false;
        }
    });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            final List<General> filteredList = filter(DataSupport.findAll(General.class), newText);
            adapter.setNewData(filteredList);
            adapter.notifyDataSetChanged();
            return false;
        }
    });
    return super.onCreateOptionsMenu(menu);
}
 
开发者ID:wmgylc,项目名称:The-Three-kingdoms-Generals-Dictionary,代码行数:38,代码来源:MainActivity.java

示例7: onCreateOptionsMenu

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Inflate the menu; this adds items to the action bar if it is present.
    inflater.inflate(R.menu.menu_search, menu);
    MenuItem searchMenuItem = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) searchMenuItem.getActionView();
    searchView.setQueryHint(getString(R.string.search_hint));
    searchView.setIconifiedByDefault(false);
    ImageView search_mag_icon = (ImageView) searchView.findViewById(R.id.search_mag_icon);
    search_mag_icon.setImageResource(0);
    LinearLayout search_plate = (LinearLayout) searchView.findViewById(R.id.search_plate);
    search_plate.setBackgroundColor(Color.TRANSPARENT);
    searchView.setOnQueryTextListener(mQueryListener);
}
 
开发者ID:XYScience,项目名称:StopApp,代码行数:15,代码来源:AppListFragment.java

示例8: onCreateOptionsMenu

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem searchMenuItem = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) searchMenuItem.getActionView();
    searchView.setQueryHint(getString(R.string.search_hint));
    searchView.setIconifiedByDefault(false);
    ImageView search_mag_icon = (ImageView) searchView.findViewById(R.id.search_mag_icon);
    search_mag_icon.setImageResource(0);
    LinearLayout search_plate = (LinearLayout) searchView.findViewById(R.id.search_plate);
    search_plate.setBackgroundColor(Color.TRANSPARENT);
    searchView.setOnQueryTextListener(mQueryListener);
    return true;
}
 
开发者ID:XYScience,项目名称:StopApp,代码行数:16,代码来源:MainActivity.java

示例9: initSearchView

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
private void initSearchView() {
    SearchView searchView = mBinding.svSearch;
    //设置搜索框左边距
    LinearLayout editFrame = (LinearLayout) findViewById(R.id.search_edit_frame);
    LinearLayout.LayoutParams editP = (LayoutParams) editFrame.getLayoutParams();
    editP.leftMargin = 0;
    editP.rightMargin = 0;
    ImageView imageView = (ImageView) findViewById(R.id.search_mag_icon);
    imageView.setAdjustViewBounds(true);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    LinearLayout.LayoutParams lp3 = (LayoutParams) imageView.getLayoutParams();
    lp3.gravity = Gravity.CENTER_VERTICAL;
    lp3.leftMargin = (int) (DensityUtil.dip2px(8f) * DensityUtil.getBaseScale(getContext()));
    lp3.rightMargin = (int) (DensityUtil.dip2px(-2f) * DensityUtil.getBaseScale(getContext()));

    View view = searchView.findViewById(R.id.search_plate);
    view.setBackgroundColor(getResources().getColor(R.color.colorTransparent));
    EditText editText = (EditText) searchView.findViewById(R.id.search_src_text);
    editText.setBackgroundColor(Color.TRANSPARENT);
    editText.setTextSize(11.5f);
    editText.setTextColor(getResources().getColor(R.color.colorText));
    editText.setHintTextColor(getResources().getColor(R.color.colorHint));
    try {
        Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
        fCursorDrawableRes.setAccessible(true);
        int mCursorDrawableRes = fCursorDrawableRes.getInt(editText);
        Field fEditor = TextView.class.getDeclaredField("mEditor");
        fEditor.setAccessible(true);
        Object editor = fEditor.get(editText);
        Class<?> clazz = editor.getClass();
        Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
        fCursorDrawable.setAccessible(true);
        if (mCursorDrawableRes <= 0) return;
        Drawable cursorDrawable = ContextCompat.getDrawable(searchView.getContext(), mCursorDrawableRes);
        if (cursorDrawable == null) return;
        Drawable tintDrawable = DrawableCompat.wrap(cursorDrawable);
        DrawableCompat.setTintList(tintDrawable, ColorStateList.valueOf(ContextCompat.getColor(getContext(), R.color.bg_search)));
        Drawable[] drawables = new Drawable[]{tintDrawable, tintDrawable};
        fCursorDrawable.set(editor, drawables);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
开发者ID:xieyangxuejun,项目名称:SearchLayout,代码行数:44,代码来源:FlowSearchLayout.java

示例10: onCreateOptionsMenu

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
            getMenuInflater().inflate(R.menu.white_list_activity_menu, menu);
            SearchManager searchManager =
                    (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            final SearchView searchView = (SearchView) menu.findItem(R.id.ab_search).getActionView();

            selectAll=menu.findItem(R.id.select_all);
            setSelection=menu.findItem(R.id.setSelection);

            final SearchView.SearchAutoComplete searchEditText = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);

            searchEditText.setTextColor(getResources().getColor(R.color.white));
            searchView.setQueryHint("Search");

            // 将搜索按钮放到搜索输入框的外边
            searchView.setIconifiedByDefault(false);


            searchView.setSearchableInfo(
                    searchManager.getSearchableInfo(getComponentName()));
            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String newText) {
                    refreshListByQuery(searchView.getQuery().toString());
                    return true;
                }
            });
            searchView.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    refreshListByQuery("");
                    return false;
                }
            });

//            MenuItem menuItem=menu.add("恢复默认");
//            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
//            menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
//                @Override
//                public boolean onMenuItemClick(MenuItem item) {
//                    if(mSelectedApplicationInfos==null){
//                        SnackBarUtil.show(toolbar,R.string.wait_until_loaded);
//                        return true;
//                    }
//                    for (AppListAdapter.ApplicationInfoWrap app:mSelectedApplicationInfos){
//                        app.isSelected=false;
//                    }
//                    mSelectedApplicationInfos.clear();
//                    mAppAdapter.notifyDataSetChanged();
//                    refreshTV();
//                    return true;
//                }
//            });
        }
        refreshMenu(false);
        return true;
    }
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:65,代码来源:FloatViewWhiteListActivity.java

示例11: onCreateOptionsMenu

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
            getMenuInflater().inflate(R.menu.white_list_activity_menu, menu);
            SearchManager searchManager =
                    (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            final SearchView searchView = (SearchView) menu.findItem(R.id.ab_search).getActionView();

            selectAll=menu.findItem(R.id.select_all);
            setSelection=menu.findItem(R.id.setSelection);

            final SearchView.SearchAutoComplete searchEditText = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);

            searchEditText.setTextColor(getResources().getColor(R.color.white));
            searchView.setQueryHint("Search");

            // 将搜索按钮放到搜索输入框的外边
            searchView.setIconifiedByDefault(false);


            searchView.setSearchableInfo(
                    searchManager.getSearchableInfo(getComponentName()));
            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String newText) {
                    refreshListByQuery(searchView.getQuery().toString());
                    return true;
                }
            });
            searchView.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    refreshListByQuery("");
                    return false;
                }
            });

//            MenuItem menuItem=menu.add("恢复默认");
//            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
//            menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
//                @Override
//                public boolean onMenuItemClick(MenuItem item) {
//                    if(mSelectedApplicationInfos==null){
//                        SnackBarUtil.show(toolbar,R.string.wait_until_loaded);
//                        return true;
//                    }
//                    for (AppListAdapter.ApplicationInfoWrap app:mSelectedApplicationInfos){
//                        app.isSelected=false;
//                    }
//                    mSelectedApplicationInfos.clear();
//                    mAppAdapter.notifyDataSetChanged();
//                    refreshTV();
//                    return true;
//                }
//            });
        }
        setSelection.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                showPopupMenu(toolbar);
                return true;
            }
        });
        refreshMenu(false);
        return true;
    }
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:72,代码来源:WhiteListActivity.java


注:本文中的android.support.v7.widget.SearchView.findViewById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。