2014-10-01 6 views
4

내 액티비티에서 SearchView를 사용하고 있습니다. 사용자가 입력 할 때 서버에 대한 검색 요청을 수행하고 있습니다. 나는 어떤 활동이 일어나고 있음을 지적하고자한다. SearchView에서 진행 스피너를 표시 할 수 있습니까?진행률 회 전자를 SearchView에 넣으시겠습니까?

그렇지 않으면 사람들이 어떻게 처리하나요? 사용자 정의 액션 바 부모 레이아웃을 만들고 SearchView를 퍼가 는가?

<LinearLayout orientation="horizontal"> 
    <SearchView /> 
    <ProgressBar /> 
</LinearLayout> 

나는 그것이 SearchView 내에 있지 않은 것을 알고

답변

6

먼저 진행 표시 줄 레이아웃을 만듭니다. 이 같은 XML은 작업을 수행해야합니다

R.layout.loading_icon

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ProgressBar 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_width="25dp" 
     android:layout_height="25dp" 
     android:id="@+id/search_progress_bar" 
     android:layout_marginTop="5dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" /> 
</RelativeLayout> 

다음 두 가지 기능을 만들 수 있습니다. 하나는 searchview에 진행 표시 줄을 표시하고 다른 하나는 그것을 숨길 수 :

public void showProgressBar(SearchView searchView, Context context) 
{ 
    int id = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null); 
    if (searchView.findViewById(id).findViewById(R.id.search_progress_bar) != null) 
     searchView.findViewById(id).findViewById(R.id.search_progress_bar).animate().setDuration(200).alpha(1).start(); 

    else 
    { 
     View v = LayoutInflater.from(context).inflate(R.layout.loading_icon, null); 
     ((ViewGroup) searchView.findViewById(id)).addView(v, 1); 
    } 
} 
public void hideProgressBar(SearchView searchView) 
{ 
    int id = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null); 
    if (searchView.findViewById(id).findViewById(R.id.search_progress_bar) != null) 
     searchView.findViewById(id).findViewById(R.id.search_progress_bar).animate().setDuration(200).alpha(0).start(); 
} 
+0

이 솔루션은 Google이 "search_plate"가 변경된 곳의 업데이트를 공개하지 않는다고 생각합니다. – user3203425

+0

예. Google sdk에서 대처하여 자신의 SearchView를 만들 수도 있습니다. –

+0

잘 했어. 감사 :) –

1

감사합니다,하지만 액션 바 여기 http://blog.denevell.org/android-progress-spinner.html 발견이 진행 표시를 제공하기 위해 지금까지 가장 간단한 방법입니다 :

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 
    setContentView(R.layout.activity_main); 

    // Turn it on 
    setProgressBarIndeterminateVisibility(true); 
    // And when you want to turn it off 
    setProgressBarIndeterminateVisibility(false); 
} 

하는 경우 당신은 정말로 SearchView 내부에 진도가 나타나기를 바라고 LinearLayout (또는 부모로서 atleast) 대신 FrameLayout을 사용할 수 있다고 가정하고, XML의 하단에 진행을 두어 SearchView 맨 위에 놓습니다. .

0

당신이 android.support.v7.widget.SearchView을 확장하는 사용자 정의 SearchView 클래스를 사용하는 경우, 당신은이 작업을 수행해야합니다 :

public void init(Context context){ 

     EditText searchPlate = (EditText) findViewById(android.support.v7.appcompat.R.id.search_src_text); 
     //searchPlate.setHint("Search"); 
     mSearchPlateView = findViewById(android.support.v7.appcompat.R.id.search_plate); 
     mSearchPlateView.setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent)); 
    } 
public void showProgressBar(Context context) { 

     if (mProgressBar != null) { 
      mProgressBar.animate() 
        .setDuration(200) 
        .alpha(1) 
        .start(); 
     } 
     else { 
      RelativeLayout relativeLayout = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.invest_progress_loading, null); 
      mProgressBar = (ProgressBar) relativeLayout.findViewById(R.id.search_progress_bar); 
      ((ViewGroup) mSearchPlateView).addView(relativeLayout, 1); 
     } 
    } 

    public void hideProgressBar() { 

     if(mProgressBar == null) 
      return; 

     mProgressBar.animate() 
        .setDuration(200) 
        .alpha(0) 
        .start(); 

    } 
관련 문제