2014-06-17 76 views
1

我有什麼是一個動作欄..我只有它的標誌和一個圖像按鈕,我想當我按下按鈕一個微調三個值將出現和他們每個人開一個新的活動,這裏是我的代碼:下拉菜單上的圖像按鈕上的操作欄

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    android.app.ActionBar mActionBar = getActionBar(); 
    mActionBar.setDisplayShowHomeEnabled(false); 
    mActionBar.setDisplayShowTitleEnabled(false); 
    LayoutInflater mInflater = LayoutInflater.from(this); 

    View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null); 
    TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text); 
    mTitleTextView.setText("My Own Title"); 

    ImageButton imageButton = (ImageButton) mCustomView 
      .findViewById(R.id.imageButton); 
    imageButton.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View view) { 
    // i want the spinner to be add here 
     } 
    }); 

    mActionBar.setCustomView(mCustomView); 
    mActionBar.setDisplayShowCustomEnabled(true); 
} 

@Override 
public boolean onNavigationItemSelected(int arg0, long arg1) { 
    // TODO Auto-generated method stub 
    return false; 
} 

回答

0

ublic類MainActivity擴展活動{ ... ...

/** 
* On selecting action bar icons 
* */ 
@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Take appropriate action for each action item click 
    switch (item.getItemId()) { 
    case R.id.action_search: 
     // search action 
     return true; 
    case R.id.action_location_found: 
     // location found 
     LocationFound(); 
     return true; 
    case R.id.action_refresh: 
     // refresh 
     return true; 
    case R.id.action_help: 
     // help action 
     return true; 
    case R.id.action_check_updates: 
     // check for updates action 
     return true; 
    default: 
     return super.onOptionsItemSelected(item); 
    } 
} 

/** 
* Launching new activity 
* */ 
private void LocationFound() { 
    Intent i = new Intent(MainActivity.this, LocationFound.class); 
    startActivity(i); 
} 

}

試試這個代碼:

爲了更好地理解經歷以下鏈接 http://www.androidhive.info/2013/11/android-working-with-action-bar/

+0

這是不從圖像按鈕開始微調..其只能用3值和第一值的微調將始終會被顯示..所以我該怎麼做? – user3675605

+0

我已更改代碼...現在嘗試... 請通過此lnk http://www.androidhive.info/2013/11/android-working-with-action-bar/ –

+0

您只是複製代碼..這不是我所需要的 – user3675605