2016-06-13 2 views
-1
내 응용 프로그램에서 검색을 구현해야

처럼 플레이 구현하고 사람이 수행하는 방법을 나에게 설명 할 정도로 관심을하시기 바랍니다 것입니다 그것은이어떻게 구글은 검색 창

Google play store search bar

처럼 보일 것입니다. ?? 미리 감사드립니다.

+0

당신은 여기에 대해 읽을 수 있습니다 : https : //로 개발자 .android.com/guide/topics/search/search-dialog.html – REG1

+1

[액션 바에서 SearchView 구현하기] 중복 가능 (http://stackoverflow.com/questions/21585326/implementing-searchview-in-action-bar) – JonasCz

답변

1

맞춤 레이아웃을 만들 수 있습니다. 1. 상대 레이아웃을 사용하고 둥근 테두리가있는 배경을 지정합니다. 2. 햄버거 아이콘을 왼쪽에 추가하십시오. 3. 마이크 아이콘을 오른쪽에 추가하십시오. 4. 가운데에 편집 문구를 추가하십시오. 다음 햄버거 아이콘과 마이크 아이콘을 수동으로 클릭하여 처리하십시오.

정확하게 동일하지는 않지만 편집하고 변경할 수있는 코드가 있습니다.

<RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginLeft="@dimen/activity_horizontal_margin" 
      android:layout_marginRight="@dimen/activity_horizontal_margin" 
      android:background="@drawable/editext_border"> 

      <ImageView 
       android:id="@+id/iv_search_mic" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_centerVertical="true" 
       android:src="@drawable/ic_mic_green" /> 

      <EditText 
       android:id="@+id/ed_home_searchbar" 
       fontPath="fonts/weblysleekuisl.ttf" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_toLeftOf="@+id/iv_search_icon" 
       android:layout_toRightOf="@+id/iv_search_mic" 
       android:background="@android:color/transparent" 
       android:hint="@string/action_search" 
       android:imeOptions="actionSearch" 
       android:padding="10dp" 
       android:singleLine="true" 
       android:textColor="@color/colorText" 
       android:textCursorDrawable="@drawable/color_cursor" 
       android:textSize="@dimen/text_xxsmall" /> 

      <ImageView 
       android:id="@+id/iv_search_icon" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" 
       android:src="@drawable/ic_search_green" /> 

     </RelativeLayout> 

다음 열기 구글 음성 마이크 클릭

searchMic.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       OnSwap.getInstance().trackEvent(TAG, "searchMic", "searchMic Clicked"); 
       Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
       intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 
         RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 
       intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Search"); 
       startActivityForResult(intent, VOICE_INPUT_REQUEST_CODE); 
      } 
     }); 

의 검색과 같은 클릭 이벤트를 처리하여 onActivityResult 방법

if (requestCode == VOICE_INPUT_REQUEST_CODE) { 
      if (resultCode == RESULT_OK) { 
       ArrayList<String> matches = data.getStringArrayListExtra(
         RecognizerIntent.EXTRA_RESULTS); 
       int matchSize = matches.size(); 
       for (int index = 0; index < matchSize; index++) { 
        Log.i(TAG, String.valueOf(index) + ": " + matches.get(index)); 
        if (index == 0) { 
         searchbar.setText(matches.get(index)); 
        } 
       } 
      } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) { 
       Status status = PlaceAutocomplete.getStatus(this, data); 
       // TODO: Handle the error. 
       Log.i(TAG, status.getStatusMessage()); 
       Snackbar.make(locationTextView, status.getStatusMessage(), Snackbar.LENGTH_LONG).show(); 

      } else if (resultCode == RESULT_CANCELED) { 
       Snackbar.make(locationTextView, "Canceled", Snackbar.LENGTH_LONG).show(); 
      } 
     } 
+0

Thnks mate .... 나는이 수색 것에서 몇몇 온라인 docs를 따르지 않을 것이다. – Infamous

+0

친구에게 도와 줘서 고맙습니다 :) – Shubham