Java Code Examples for android.support.v7.widget.SearchView#setMaxWidth()

The following examples show how to use android.support.v7.widget.SearchView#setMaxWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From HideMockLocation with MIT License 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.action_menu, menu);

    final MenuItem searchItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    // Resize searchView
    searchView.setMaxWidth(Integer.MAX_VALUE);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            adapter.filter(query);
            searchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            adapter.filter(newText);
            return true;
        }
    });
    return true;
}
 
Example 2
Source File: SearchMusicActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search_music, menu);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setMaxWidth(Integer.MAX_VALUE);
    searchView.onActionViewExpanded();
    searchView.setQueryHint(getString(R.string.search_tips));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            searchMusic(query);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    searchView.setSubmitButtonEnabled(true);
    try {
        Field field = searchView.getClass().getDeclaredField("mGoButton");
        field.setAccessible(true);
        ImageView mGoButton = (ImageView) field.get(searchView);
        mGoButton.setImageResource(R.drawable.ic_menu_search);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return super.onCreateOptionsMenu(menu);
}
 
Example 3
Source File: HomeFragment.java    From mobikul-standalone-pos with MIT License 4 votes vote down vote up
@Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        final MenuItem searchItem = menu.findItem(R.id.menu_item_search);
        searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        searchItem.setVisible(true);
        searchItem.expandActionView();
        searchView.setQueryHint("Search your product...");
        ((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(getResources().getColor(R.color.colorAccent));
        searchView.setMaxWidth(Integer.MAX_VALUE);
        searchProduct = new ArrayList<>();

        searchView.setOnSearchClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //perform your click operation hereif (mMainBinding.drawerLayout != null &&
                if (((MainActivity) getActivity()).mMainBinding.drawerLayout.isDrawerOpen(GravityCompat.START))
                    ((MainActivity) getActivity()).mMainBinding.drawerLayout.closeDrawer(GravityCompat.START);

            }
        });

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

            @Override
            public boolean onQueryTextChange(String newText) {
                if (newText.length() > 0) {
                    newText = "%" + newText + "%";
                    DataBaseController.getInstanse().getSearchData(getActivity(), newText, new DataBaseCallBack() {
                        @Override
                        public void onSuccess(Object responseData, String successMsg) {
                            if (!(searchProduct.toString().equalsIgnoreCase(responseData.toString()))) {
                                if (searchProduct.size() > 0) {
                                    searchProduct.clear();
                                }
                                searchProduct.addAll((List<Product>) responseData);
                                productAdapter = new HomePageProductAdapter(getActivity(), searchProduct);
                                binding.productRv.setAdapter(productAdapter);
                            }
                        }

                        @Override
                        public void onFailure(int errorCode, String errorMsg) {

                        }
                    });
                    return true;
                } else {
                    productAdapter = new HomePageProductAdapter(getActivity(), products);
                    binding.productRv.setAdapter(productAdapter);
                }
                return false;
            }
        });

        final MenuItem barCodeItem = menu.findItem(R.id.menu_item_scan_barcode);
        barCodeItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
//                Intent intent = new Intent("com.google.zxing.client.android.SCAN");
//                intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
//                startActivityForResult(intent, 0);
                Intent intent = new Intent(getActivity(), BarcodeCaptureActivity.class);
                getActivity().startActivityForResult(intent, BARCODE_READER_REQUEST_CODE);
                return false;
            }
        });
    }
 
Example 4
Source File: OrdersFragment.java    From mobikul-standalone-pos with MIT License 4 votes vote down vote up
@Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        final MenuItem barcodeItem = menu.findItem(R.id.menu_item_scan_barcode);
        barcodeItem.setVisible(false);
        final MenuItem searchItem = menu.findItem(R.id.menu_item_search);
        searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        searchItem.setVisible(true);
        searchItem.expandActionView();
        searchView.setQueryHint("Search your order...");
        ((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(getResources().getColor(R.color.colorAccent));
        searchView.setMaxWidth(Integer.MAX_VALUE);
        searchOrders = new ArrayList<>();
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                if (newText.length() > 0) {
                    newText = "%" + newText + "%";
                    DataBaseController.getInstanse().getSearchOrders(getActivity(), newText, new DataBaseCallBack() {
                        @Override
                        public void onSuccess(Object responseData, String successMsg) {
                            if (!(searchOrders.toString().equalsIgnoreCase(responseData.toString()))) {
                                if (searchOrders.size() > 0) {
                                    searchOrders.clear();
                                }
                                searchOrders.addAll((List<OrderEntity>) responseData);
                                orderAdapter = new OrderAdapter(getActivity(), searchOrders);
                                binding.orderRv.setAdapter(orderAdapter);
//                                orderAdapter.notifyDataSetChanged();
                            }
                        }

                        @Override
                        public void onFailure(int errorCode, String errorMsg) {

                        }
                    });
                    return true;
                } else {
                    orderAdapter = new OrderAdapter(getActivity(), orders);
                    binding.orderRv.setAdapter(orderAdapter);
                }
                return false;
            }
        });

    }
 
Example 5
Source File: MainActivity.java    From AndroidHttpCapture with MIT License 4 votes vote down vote up
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);

//        MenuItem pageButton = menu.findItem(R.id.action_page);
//        pageButton.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
//            @Override
//            public boolean onMenuItemClick(MenuItem item) {
//                createPage();
//                return true;
//            }
//        });

        filterMenuItem = menu.findItem(R.id.action_filter);
        homeItem = menu.findItem(R.id.action_home);
        searchItem = menu.findItem(R.id.search);
//        uaMenuItem = menu.findItem(R.id.ua);
//        logMenuItem = menu.findItem(R.id.log);

        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        searchView = (SearchView) searchItem.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setFocusable(false);
        searchView.setIconifiedByDefault(true);
        searchView.setMaxWidth(Integer.MAX_VALUE);
        searchView.setQueryHint("请输入URL关键字...");

        searchView.setOnSearchClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchContent(PreviewFragment.getInstance());
            }
        });

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                PreviewFragment.getInstance().filterItem(query);
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                PreviewFragment.getInstance().filterItem(newText);
                shouldExitSearchView = newText.length() == 0;
                return false;
            }
        });
        return true;
    }
 
Example 6
Source File: AtUserFragment.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void showSearchMenu(Menu menu) {
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setIconifiedByDefault(false);
    searchView.setSubmitButtonEnabled(false);
    searchView.setMaxWidth(Utility.dip2px(200));
    // searchView.setQueryHint(getString(R.string.at_other));

    // searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // searchView.setIconifiedByDefault(false);
    // searchView.setQueryHint(getString(R.string.at_other));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!TextUtils.isEmpty(newText)) {
                if (task != null) {
                    task.cancel(true);
                }
                task = new AtUserTask(newText);
                task.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                if (task != null) {
                    task.cancel(true);
                }
                atList.clear();
                result.clear();
                atList = AtUsersDBTask.get(BeeboApplication.getInstance().getCurrentAccountId());
                for (AtUserBean b : atList) {
                    result.add(b.getNickname());
                }
                adapter.notifyDataSetChanged();
            }
            return false;
        }
    });
    searchView.requestFocus();
}
 
Example 7
Source File: AtUserFragment.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void showSearchMenu(Menu menu) {
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setIconifiedByDefault(false);
    searchView.setSubmitButtonEnabled(false);
    searchView.setMaxWidth(Utility.dip2px(200));
    // searchView.setQueryHint(getString(R.string.at_other));

    // searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // searchView.setIconifiedByDefault(false);
    // searchView.setQueryHint(getString(R.string.at_other));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!TextUtils.isEmpty(newText)) {
                if (task != null) {
                    task.cancel(true);
                }
                task = new AtUserTask(newText);
                task.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                if (task != null) {
                    task.cancel(true);
                }
                atList.clear();
                result.clear();
                atList = AtUsersDBTask.get(BeeboApplication.getInstance().getCurrentAccountId());
                for (AtUserBean b : atList) {
                    result.add(b.getNickname());
                }
                adapter.notifyDataSetChanged();
            }
            return false;
        }
    });
    searchView.requestFocus();
}