2014-01-29 72 views
2

[AS-是圖像] http://sdrv.ms/1bx8Bxm [待圖像] http://sdrv.ms/1aGADfo 我們想從上下文中移動保持按鈕頭。我們嘗試了很多方法。一些示例代碼,但一旦我們添加到我們的代碼中就會出錯。任何人都可以幫助我們嗎? 第一張圖片就是我們現在的樣子,第二張圖片就是我們想要的圖片。 非常感謝你!如何在頭部添加按鈕

enter image description here

enter image description here

我們對保持XML按鈕的代碼是這樣的:

<Button 
android:id="@+id/maintain" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentRight="true" 
android:layout_alignParentTop="true" 
android:text="Maintain" 
android:background="#F77D03" /> 
+2

哪裏是你的代碼?你試過了什麼? –

+0

看起來像一個按鈕在操作欄 – Raghunandan

+1

爲什麼不使用菜單選項? – keshav

回答

0

將這個代碼在資源 main1.xml的菜單文件夾

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item 
     android:id="@+id/action_maintain" 
     android:showAsAction="always" 
     android:title="Maintain"/> 

</menu> 

而這Activity

@Override 
    public boolean onCreateOptionsMenu(Menu menu) 
    { 
     getMenuInflater().inflate(R.menu.main1, menu);// Menu Resource, Menu 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) 
    { 
     switch(item.getItemId()) 
     { 
     case R.id.action_maintain: 
      Toast.makeText(getApplicationContext(), "Item 1 Selected", Toast.LENGTH_LONG).show(); 
      return true; 

     default: 
      return super.onOptionsItemSelected(item); 
     } 
    } 
+0

嗨!謝謝你的幫助!這非常有用!但現在我們的標題:如下面的示例NextBusStopV1消失。現在我們的界面就像這個http://sdrv.ms/1goZ1nW。我們應該做什麼? – kassiopite

+0

它已經有什麼問題了?第一個屏幕是一樣的。 – keshav

+0

在我們的原始版本中有一個「NextBusStopV1」,但現在消失了,所以我該怎麼辦?我需要在上面顯示,謝謝。所以我們的目標標題實際上是NextBusStopV1,除此之外,右側的維護按鈕 – kassiopite