2014-01-29 91 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