2012-07-07 83 views
3

你好我想把按鈕旁邊的活動標題在android中。我可以使用setTitle()更改文本,但是我沒有找到任何允許將按鈕放在Activity標題旁邊的任何東西。我正在使用android 4.0.3。有誰能夠幫助我?如何把按鈕旁邊的活動標題放在android中?

enter image description here

+1

使用'自定義標題欄' – 2012-07-07 08:55:38

回答

6

在您的項目名稱topbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="40dp" 
    android:orientation="vertical" 
    android:background="@android:color/white"> 

    <TextView 
     android:id="@+id/title_txt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="MyTitle: NameOfUser" 
     android:layout_centerVertical="true" 
     android:textColor="@android:color/black" 
     android:textStyle="bold" 
     android:textSize="20sp" 
     android:layout_marginLeft="20dp"/> 


    <Button 
     android:id="@+id/back_btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:text="Btn" 
     android:textColor="@android:color/white" 
     android:layout_marginLeft="5dp" 
     android:layout_alignParentRight="true"/> 
</RelativeLayout> 

創建XML文件,並在任何添加此佈局佈局只寫:

<include layout="@layout/topbar"/> 

希望這會對你有幫助。

+0

其他答案將工作,但在andoridmenifest.xml中使用NoTitle主題影響我目前的主題,我不想要。所以現在我使用this.requestWindowFeature(Window.FEATURE_NO_TITLE)刪除默認標題欄;該dosent影響我的默認主題幷包含佈局文件。 謝謝AkashG。 – 2012-07-07 09:35:07

相關問題