2014-07-21 2 views
0

기본 검색보기 아이콘에 문제가 있습니다. 응용 프로그램의 아이콘을 변경하고 기본값 대신 사용자 정의 드로어 블을 사용하고 싶습니다. 도움을기본 검색보기 아이콘 변경 안드로이드

<SearchView 
        android:id="@+id/searchView1" 
        android:layout_width="wrap_content" 
        android:layout_height="35dp" 
        android:layout_marginBottom="10dp" 
        android:layout_marginTop="10dp" > 
       </SearchView> 

감사 :

나는 XML을 사용하고 있습니다. 여기

+0

이 링크를 클릭하면 맞춤 검색보기로 이동할 수 있습니다. http://www.codeproject.com/Tips/631965/Android-Edit-Text-with-Cross-Icon-x 유용한 상 감성을 느낀다면 –

+0

감사합니다. 도움. 그러나 나는 searchview와 같은 기능을 원합니다. 시작에는 아이콘이 있어야하고 클릭 편집 텍스트에는 확장이 있어야합니다.이 링크는 내 시나리오에 적합하지 않습니다. – Prateek

+0

실제로 내가 기본 아이콘을 변경하는 것에 대해 이야기하고 있다고 생각하고 있었기 때문에 링크를 참조 할 수 있습니다. 사용자 정의 아이콘을 사용할 수 있지만 지금은 축소 가능한 SearchView에 대해 이야기하고 있기 때문입니다. 잘하면 내 도움이 될 것입니다. –

답변

1

내가

당신의 activity_main.xml 레이아웃처럼 WHATSAPP에 사용 searchView에 대한 코드를 제공하고

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
    <TextView 
      android:id="@+id/status_text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal"/> 
</LinearLayout> 

메뉴 폴더에 searchview_in_menu.xml

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" > 

<item android:id="@+id/action_search" 

     android:title="Search" 
     android:icon="@android:drawable/ic_menu_search" 
     android:showAsAction="always" 
     android:actionLayout="@layout/searchview_layout"/> 
</menu> 

searchview_layout.xml 레이아웃 접기 어

<?xml version="1.0" encoding="utf-8"?> 
    <SearchView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/search_view_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

당신의 MainActivity.java는

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.MenuItem; 
import android.view.Window; 
import android.widget.SearchView; 

public class MainActivity extends Activity { 
    private SearchView mSearchView; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     getWindow().requestFeature(Window.FEATURE_ACTION_BAR); 
     setContentView(R.layout.activity_main); 
    } 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     super.onCreateOptionsMenu(menu); 
     MenuInflater inflater = getMenuInflater(); 
     inflater.inflate(R.menu.searchview_in_menu, menu); 
     //find the search view item and inflate it in the menu layout 
     MenuItem searchItem = menu.findItem(R.id.action_search); 
     mSearchView = (SearchView) searchItem.getActionView(); 
     //set a hint on the search view (optional) 
     mSearchView.setQueryHint(getString(R.string.search)); 
     //these flags together with the search view layout expand the search view in the landscape mode 
     searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW 
       | MenuItem.SHOW_AS_ACTION_ALWAYS); 
     //expand the search view when entering the activity(optional) 
     searchItem.expandActionView(); 
     return true; 
    } 

그것이

enter image description here

enter image description here

이 당신의 목적을 제공합니다 희망 아래의 스크린 샷과 같은 결과를 생산할 예정이다.