2014-03-26 3 views

답변

0

당신이 구현하는 방법을 모르는 작은 진행 막대하지만 ... 지금까지 내가 당신이 바로, 이것에 대한있는 CustomView를 만들 필요가 알고? 이런 일이 : RefreshMenuItemHelper 같은 새로운 클래스를 만들 :

public class RefreshMenuItemHelper { 
    private WeakReference<MenuItem> item; 

    /** 
    * Set the menu item. 
    * @param item 
    */ 
    public void setMenuItem(MenuItem item) { 
     this.item = new WeakReference<MenuItem>(item); 
    } 

    /** 
    * Show the indeterminate progress. 
    */ 
    public void showLoading() { 
     if(item != null) { 
      item.get().setActionView(R.layout.menu_item_action_refresh); 
      item.get().expandActionView(); 
     } 
    } 

    /** 
    * Stop and dismiss the indeterminate progress. 
    */ 
    public void stopLoading() { 
     item.get().collapseActionView(); 
     item.get().setActionView(null); 
    } 

} 

을 menu_item_action_refresh 이런 단순한 레이아웃입니다 : 당신의

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="56dp" 
    android:layout_height="wrap_content" 
    android:minWidth="56dp"> 
    <ProgressBar 
     android:layout_width="32dp" 
     android:layout_height="32dp" 
     android:layout_gravity="center"/> 
</FrameLayout> 

그리고 마지막으로 : 이제

@Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
      case R.id.action_refresh: 
       refreshHelper.setMenuItem(item); 
      default: 
       return super.onOptionsItemSelected(item); 
     } 
    } 

당신이 할 수있는 showLoading() 및 stopLoading()을 사용하여 불확정 진행을 시작하거나 중지하십시오. 또한 menu.xml에 R.id.action_refresh에 ic_refresh.png가 있는지 확인하십시오.

희망이 있습니다. !!!

+0

감사합니다. @ nicolas-jafelle! 나는이 해결책을 시도하고 결과에 대해 논평 할 것이다. 작은 진행 대화 상자는 android가 supportRequestWindowFeature (Window.FEATURE_INDETERMINATE_PROGRESS)와 함께 제공하는 메뉴입니다. 및 setSupportProgressBarIndeterminateVisibility (true); http://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html#setSupportProgressBarIndeterminateVisibility(boolean) – benoffi7

+0

좋은 결과를 얻지 못했지만 ... = D –

+0

코드를 추가하십시오. refreshHelper 변수와 관련된. null 포인터를 사용하고 싶습니다. 감사! 나는 클래스를 만들고 메뉴 항목을 설정하지만 showLoading()의 사용은 사용자가 oncreate() 메뉴의 항목을 – benoffi7

관련 문제