如何在搜索视图中设置多个按钮?

实际上我想制作一个操作栏,当我添加下拉菜单时,其中应该有下拉菜单、搜索选项、菜单选项和另一个图标,搜索栏不在完整的操作栏上。当我单击搜索图标时,搜索视图应该在完整的操作栏上,但只有一半被下拉菜单覆盖


这是java代码


@Override

    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.

        getMenuInflater().inflate(R.menu.mainpage, menu);

        getMenuInflater().inflate(R.menu.android_action_bar_spinner_menu, menu);


        MenuItem item = menu.findItem(R.id.spinner);

        Spinner spinner = (Spinner) MenuItemCompat.getActionView(item);


        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,

                R.array.dropdown, android.R.layout.simple_spinner_item);

        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        spinner.setAdapter(adapter);

        // Inflate the menu; this adds items to the action bar if it is present.

        getMenuInflater().inflate(R.menu.menu_search, menu);


        MenuItem search_item = menu.findItem(R.id.mi_search);


        SearchView searchView = (SearchView) search_item.getActionView();

        searchView.setFocusable(false);

        searchView.setQueryHint("Search");

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {



            @Override

            public boolean onQueryTextSubmit(String s) {


                //clear the previous data in search arraylist if exist

                Toast.makeText(MainpageActivity.this, s, Toast.LENGTH_SHORT).show();

                     return false;

            }


            @Override

            public boolean onQueryTextChange(String s) {

                Toast.makeText(MainpageActivity.this, s, Toast.LENGTH_SHORT).show();

                return false;

            }

        });



        return true;


    }

慕哥6287543
浏览 160回答 4
4回答

慕的地10843

这是从网络摄像头捕获图像的示例。这是更新的、面向对象的、整合的 OpenCV 2 Python API。import cv2# Camera 0 is your port number&nbsp;camera_port = 0#Number of frames to throw away while the camera adjusts to light levelsramp_frames = 30# Initialize cam with portcamera = cv2.VideoCapture(camera_port)# Captures a single image & returns&nbsp; in PIL formatdef get_image():# read full image out of a VideoCapture object.retval, im = camera.read()return im# Ramp the camera - these frames will be discarded and are only used to allow v4l2for i in xrange(ramp_frames):temp = get_image()print("Taking image...")# Take the actual image we want to keepcamera_capture = get_image()file = "/home/codeplasma/test_image.png"# correct format based on the file extension you provide. Convenient!cv2.imwrite(file, camera_capture)# capture object until your script exitsdel(camera)

慕妹3146593

也许,您应该阅读官方文档。你试试这段代码。祝你好运!import cv2cap = cv2.VideoCapture(0)while(True):&nbsp; &nbsp; # Capture frame-by-frame&nbsp; &nbsp; ret, frame = cap.read()&nbsp; &nbsp; # Display the resulting frame&nbsp; &nbsp; cv2.imshow('frame',frame)&nbsp; &nbsp; cv2.imread('./your-dir/image.png', frame)&nbsp; &nbsp; if cv2.waitKey(1) & 0xFF == ord('q'):&nbsp; &nbsp; &nbsp; &nbsp; break# When everything done, release the capturecap.release()cv2.destroyAllWindows()

牛魔王的故事

import numpy as npimport cv2cap = cv2.VideoCapture(0)while(True):&nbsp; &nbsp; &nbsp;# Capture frame-by-frame&nbsp; &nbsp; &nbsp;ret, frame = cap.read()# Our operations on the frame come heregray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)# Display the resulting framecv2.imshow('frame',gray)#this line save your image into Dircv2.imwrite("you dir path eg. C:\", img)if cv2.waitKey(1) & 0xFF == ord('q'):&nbsp; &nbsp; break# When everything done, release the capturecap.release()cv2.destroyAllWindows()

当年话下

首先尝试像管理员一样运行 python 的 shell/console 来执行脚本:这段代码应该运行良好:import cv2 #to take photos or pre-process it with some computer vision techniqueimport os #to save images at any path i.g E:/myfolder/images/import argparse #to receive parameters in the console#Open the camera:cam = cv2.VideoCapture(0)ap = argparse.ArgumentParser()ap.add_argument("-c", "--quantity", required=True, help="Set the quantity of images that you want to take p. ej. 350")args = vars(ap.parse_args())#set path where we are going to save the image.outDirectory = "E:/alxor/"def takePhoto(number):&nbsp; &nbsp; if cam.isOpened():&nbsp; &nbsp; &nbsp; &nbsp; print("Camera opened successfully!")&nbsp; &nbsp; &nbsp; &nbsp; #Get one image:&nbsp; &nbsp; &nbsp; &nbsp; ret, frame = cam.read()&nbsp; &nbsp; &nbsp; &nbsp; name = "image_"+str(number)+".jpg"&nbsp; &nbsp; &nbsp; &nbsp; print(name)&nbsp; &nbsp; &nbsp; &nbsp; cv2.imwrite(os.path.join(outDirectory, name), frame)&nbsp; &nbsp; else:&nbsp; &nbsp; &nbsp; &nbsp; print("[INFO] Can not open the camera :(")c = int(args["quantity"])j = 1while j <= c: #introduciendo 's' salimos del bucle&nbsp; &nbsp; print ("[INFO] WRITE 's' TO EXIT: ")&nbsp; &nbsp; print ("[INFO] WRITE 'c' TO TAKE A PHOTO ")&nbsp; &nbsp; user_input = input() #leer entrada&nbsp; &nbsp; if user_input is 'c':&nbsp; &nbsp; &nbsp; &nbsp; takePhoto(j)&nbsp; &nbsp; &nbsp; &nbsp; print("[INFO] IMAGE #"+str(j)+" SAVED...")&nbsp; &nbsp; if user_input is 's':&nbsp; &nbsp; &nbsp; &nbsp; break&nbsp; &nbsp; &nbsp; &nbsp; print("[INFO] THE PROGRAM HAS FINISHED..")&nbsp; &nbsp; j+=1#Turn off the camera..cam.release()print("[INFO] THE PROGRAM HAS FINISHED..")更新 1. 使用 os 库将图像保存在所需路径中。更新 2. 拍摄 n 张图像的选项我也在 github 中留下了这段代码:&nbsp;代码
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go