簡體   English   中英

如何在Android中的活動titile旁邊放置按鈕?

[英]how to put button beside activity titile in android?

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

在此輸入圖像描述

在項目名稱topbar.xml中創建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>

只需編寫以下內容即可在任何布局中添加此布局:

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

希望這會幫助你。

您可以使用custom title bar ,也可以no title theme為活動使用no title theme ,並將線性布局設置為活動布局上方的子布局,因此您的活動似乎有標題欄

  1. 創建自定義標題欄:
    edumobile.org
    londatiga.net
  2. 隱藏申請的標題欄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM