0

내 프로젝트에서 안드로이드의 검색보기를 사용하고 있습니다. 제대로 작동하고 있습니다.안드로이드에 백 아이콘이있는 검색보기

하지만 searchview가 확장되는 동안 배경 이미지와 관련된 문제가 하나 있습니다.

enter image description here

이 아이콘 및 기타 검색 및 당김 아이콘이 내 작업 표시 줄입니다.

지금은 아이콘이 변경입니다 다음 검색 아이콘에

enter image description here

을 클릭합니다. 기본적으로 시작 프로그램 이미지를 사용합니다. 하지만 이미지 1에서 보여주는 것처럼 동일하게하고 싶습니다.

그래서이 문제를 해결하는 데 도움이 될 수 있습니다.

편집 1

여기 내 작업 표시 줄 스타일 xml입니다. 액션 바

<style name="ActionBar.Solid.Example" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
    <item name="android:icon">@drawable/ic_logo</item> 
    <item name="background">@drawable/ab_solid_example</item> 
    <item name="backgroundStacked">@drawable/ab_stacked_solid_example</item> 
    <item name="backgroundSplit">@drawable/ab_bottom_solid_example</item> 
</style> 

편집 3

이 내의 onCreateOptionsMenu의 방법에 대한

<style name="Theme.Example" parent="@style/Theme.AppCompat.Light.DarkActionBar"> 
    <item name="actionBarItemBackground">@drawable/selectable_background_example</item> 
    <item name="actionBarTabStyle">@style/ActionBarTabStyle.Example</item> 
    <item name="actionBarStyle">@style/ActionBar.Solid.Example</item> 
    <item name="actionModeBackground">@drawable/cab_background_top_example</item> 
    <item name="actionModeSplitBackground">@drawable/cab_background_bottom_example</item> 
    <item name="actionBarTabTextStyle">@style/ActionBarTabText.Example</item> 
    <!-- Light.DarkActionBar specific --> 
    <item name="android:textColorHighlight">#99c0c0c0</item> 
</style> 

EDIT2

서브 스타일. 내가 사용했던 다른 아무것도 없다

ActionBar actionBar = getSupportActionBar(); 
    SpannableString s = new SpannableString(getString(R.string.app_name)); 
    s.setSpan(new TypeFaceSpan(getContext(), 
      getString(R.string.font_gothum)), 0, s.length(), 
      Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
    actionBar.setTitle(s); 
    actionBar.setDisplayShowHomeEnabled(true); 
    actionBar.setDisplayShowTitleEnabled(true); 
    actionBar.setBackgroundDrawable(new ColorDrawable(Color 
      .parseColor("#bb0404"))); 

액션 바 및

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu items for use in the action bar 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.main, menu); 
    try { 
     search = (MenuItem) menu.findItem(R.id.search); 

     MenuItemCompat.setOnActionExpandListener(search, 
       new OnActionExpandListener() { 
        @Override 
        public boolean onMenuItemActionCollapse(MenuItem item) { 
         // Do something when collapsed 

         layoutList.setVisibility(View.INVISIBLE); 
         return true; // Return true to collapse action view 
        } 

        @Override 
        public boolean onMenuItemActionExpand(MenuItem item) { 
         // Do something when expanded 

         layoutList.setVisibility(View.VISIBLE); 
         return true; // Return true to expand action view 
        } 
       }); 

     SearchView searchView = (SearchView) MenuItemCompat 
       .getActionView(search); 

     setSearchTextColour(searchView); 

     searchView.setQueryHint(getString(R.string.search_hint)); 
     searchView.setOnQueryTextListener(this); 
     searchView.setOnCloseListener(new OnCloseListener() { 

      @Override 
      public boolean onClose() { 
       // TODO Auto-generated method stub 
       Debugger.debugE("on close"); 

       layoutList.setVisibility(View.INVISIBLE); 
       return false; 
      } 
     }); 
    } catch (Exception e) { 
     // TODO: handle exception 
    } 

    return super.onCreateOptionsMenu(menu); 
} 

를 표시합니다.

참고 : 첫 번째 이미지에 표시되는 주 화면 아이콘의 다른 모든 탐색에서 나타납니다. 문제는 searchview에서만 발생합니다.

미리 감사드립니다.

Bskania

+0

액션 바 스타일 xml을 알려주세요. –

답변

2

당신은 같은 것을 할 수

당신의 styles.xml에 앱 테마를 변경해보십시오 :

LayoutInflater inflator = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View v = inflator.inflate(R.layout.custom_search_actionbar, null); 
actionBar.setCustomView(v);    
_searchView = (SearchView)v.findViewById(R.id.searchView); 
.... 
.... 
.... 

:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> 
    <item name="android:actionBarStyle">@style/ActionBar</item> 
</style> 

<style name="ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
    <item name="android:icon">@drawable/myicon</item> 
</style> 
+0

이미 매니페스트 파일에 아이콘을 설정했습니다. 아직도 내가 이것을 바꿀 필요가 있니? – BSKANIA

+0

왜 시도하지 않으시겠습니까?)' @ style/ActionBar.Solid.Example'을 변경하여 아이콘을 정의한 사용자 정의 스타일을 만드십시오. –

+0

나는 노력했다. 그러나 그것은 작동하지 않습니다. – BSKANIA

0

사용자 정의 작업 표시 줄을 만듭니다 보기 및 사용의 ID를 정의합니다.